Serve core static files without leaving C.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4833 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-09 01:21:57 +00:00
parent e87acc6286
commit ed2d57fb4b
8 changed files with 323 additions and 48 deletions

View File

@ -102,7 +102,6 @@ typedef struct _tf_http_t
static const char* _http_connection_get_header(const tf_http_connection_t* connection, const char* name);
static void _http_connection_destroy(tf_http_connection_t* connection, const char* reason);
static const char* _http_status_text(int status);
static void _http_timer_reset(tf_http_connection_t* connection);
static void _http_tls_update(tf_http_connection_t* connection);
@ -132,8 +131,9 @@ bool _http_find_handler(tf_http_t* http, const char* path, tf_http_callback_t**
for (int i = 0; i < http->handlers_count; i++)
{
if (!http->handlers[i].pattern ||
!*http->handlers[i].pattern ||
strcmp(path, http->handlers[i].pattern) == 0 ||
(strncmp(path, http->handlers[i].pattern, strlen(http->handlers[i].pattern)) == 0 && path[strlen(http->handlers[i].pattern)] == '/'))
(*http->handlers[i].pattern && strncmp(path, http->handlers[i].pattern, strlen(http->handlers[i].pattern)) == 0 && path[strlen(http->handlers[i].pattern) - 1] == '/'))
{
*out_callback = http->handlers[i].callback;
*out_trace_name = http->handlers[i].pattern;
@ -213,7 +213,7 @@ static void _http_connection_destroy(tf_http_connection_t* connection, const cha
static void _http_builtin_404_handler(tf_http_request_t* request)
{
const char* k_payload = _http_status_text(404);
const char* k_payload = tf_http_status_text(404);
tf_http_respond(request, 404, NULL, 0, k_payload, strlen(k_payload));
}
@ -731,7 +731,7 @@ void tf_http_destroy(tf_http_t* http)
tf_free(http);
}
static const char* _http_status_text(int status)
const char* tf_http_status_text(int status)
{
switch (status)
{
@ -848,7 +848,7 @@ void tf_http_respond(tf_http_request_t* request, int status, const char** header
}
request->connection->is_response_sent = true;
const char* status_text = _http_status_text(status);
const char* status_text = tf_http_status_text(status);
/* HTTP/1.x 200 OK\r\n */
bool sent_content_length = false;
int headers_length = 8 + 1 + 3 + 1 + strlen(status_text) + 2;