add: debug logging and status cache

This commit is contained in:
Tobias Reisinger 2020-08-01 16:26:34 +02:00
parent 398019afe8
commit 9e5718db43
3 changed files with 59 additions and 15 deletions
src/handlers

View file

@ -90,6 +90,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
/* Normalize path - resolve "." and ".." (in-place). */
if (!mg_normalize_uri_path(&hm->uri, &hm->uri)) {
mg_http_send_error(nc, 400, global_config.http_server_opts.extra_headers);
LOGGER_DEBUG("failed to normalize uri %.*s\n", hm->uri.len, hm->uri.p);
return;
}
char *request_file_org = malloc(sizeof(char) * hm->uri.len);
@ -112,10 +113,12 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
{
response.status_code = 0;
mg_serve_http(nc, hm, global_config.http_server_opts);
LOGGER_DEBUG("serving %.*s\n", hm->uri.len, hm->uri.p);
return;
}
else
{
LOGGER_DEBUG("serving 'not found'\n");
endpoint = router_get_not_found_endpoint();
}
}
@ -142,10 +145,13 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
}
else
{
LOGGER_DEBUG("calling endpoint function %p\n", endpoint->func);
endpoint->func(nc, hm, endpoint->args, &response);
LOGGER_DEBUG("sending response to %p\n", nc);
send_response(nc, &response);
}
LOGGER_DEBUG("freeing endpoint args\n");
for(int i = 0; i < endpoint->args_count; ++i)
{
if(endpoint->args[i].type == ENDPOINT_ARG_TYPE_STR)
@ -169,6 +175,7 @@ handler_http(struct mg_connection *nc, int ev, void *p)
}
if(ev == MG_EV_HTTP_REQUEST)
{
LOGGER_DEBUG("new http request (%p)\n", nc);
struct http_message *hm = (struct http_message*)p;
handle_http_request(nc, hm);
}