Fixed bug with writing responses

Connections are now closed after response is send if client requested "Connection: close"
This commit is contained in:
2014-07-29 21:23:36 +01:00
parent 31e1ff4f97
commit e8d1e4d7d9
6 changed files with 23 additions and 4 deletions

View File

@@ -88,6 +88,7 @@ http_response* server_process_request(config_server* config, http_request *reque
if (filepath_actual == NULL) {
warning("realpath: not found/error", true);
response = http_response_create_builtin(404, "File not found");
http_header_list_add(response->headers, http_header_new(HEADER_CONNECTION, "close"), false);
return response;
}
//Check that the file is within the server directory of the host
@@ -116,6 +117,7 @@ http_response* server_process_request(config_server* config, http_request *reque
if (file == NULL) {
warning("failed to open file for reading", true);
response = http_response_create_builtin(404, "File not found");
http_header_list_add(response->headers, http_header_new(HEADER_CONNECTION, "close"), false);
return response;
}
@@ -141,5 +143,11 @@ http_response* server_process_request(config_server* config, http_request *reque
free(filepath_requested);
free(filepath_actual);
//Check to see if client requested the connection be closed
http_header* request_connection = http_header_list_get(request->headers, HEADER_CONNECTION);
if (request_connection != NULL && strcasecmp(request_connection->content, "close") == 0) {
http_header_list_add(response->headers, http_header_new(HEADER_CONNECTION, "close"), false);
}
return response;
}