Fix config handling
This commit is contained in:
parent
fad3d80f39
commit
fca35ade9e
18 changed files with 125 additions and 139 deletions
src/handlers
|
@ -17,16 +17,16 @@ static char*
|
|||
add_extra_headers(char *extra_headers)
|
||||
{
|
||||
char *result;
|
||||
size_t std_headers_len = strlen(global_config.http_server_opts.extra_headers);
|
||||
size_t std_headers_len = strlen(global_config->http_server_opts.extra_headers);
|
||||
if(extra_headers == NULL)
|
||||
{
|
||||
result = malloc(sizeof(char) * (std_headers_len + 1));
|
||||
strcpy(result, global_config.http_server_opts.extra_headers);
|
||||
strcpy(result, global_config->http_server_opts.extra_headers);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = malloc(sizeof(char) * (std_headers_len + strlen(extra_headers) + 3));
|
||||
sprintf(result, "%s\r\n%s", global_config.http_server_opts.extra_headers, extra_headers);
|
||||
sprintf(result, "%s\r\n%s", global_config->http_server_opts.extra_headers, extra_headers);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,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);
|
||||
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;
|
||||
}
|
||||
|
@ -105,15 +105,15 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
|
|||
++request_file;
|
||||
}
|
||||
|
||||
char *request_file_path = malloc(sizeof(char) * (strlen(request_file) + strlen(global_config.content_dir) + 2));
|
||||
sprintf(request_file_path, "%s/%s", global_config.content_dir, request_file);
|
||||
char *request_file_path = malloc(sizeof(char) * (strlen(request_file) + strlen(global_config->content_dir) + 2));
|
||||
sprintf(request_file_path, "%s/%s", global_config->content_dir, request_file);
|
||||
int access_result = access(request_file_path, R_OK);
|
||||
free(request_file_path);
|
||||
free(request_file_org);
|
||||
if(access_result != -1)
|
||||
{
|
||||
response.status_code = 0;
|
||||
mg_serve_http(nc, hm, global_config.http_server_opts);
|
||||
mg_serve_http(nc, hm, global_config->http_server_opts);
|
||||
LOGGER_DEBUG("serving %.*s\n", hm->uri.len, hm->uri.p);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue