Fix root of
@@ -117,7 +117,6 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
char buff[HTTP_BODY_CHUNK_SIZE];
http1_request_s *request = &pr->request;
char *buffer = request->buffer;
- for (;;) {
// handle requests with no file data
if (request->request.body_file <= 0) {
// request headers parsing
@@ -142,9 +141,8 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
goto finished_reading;
// parse headers
- result =
- http1_parse_request_headers(buffer, request->buffer_pos,
- &request->request, http1_on_header_found);
+ result = http1_parse_request_headers(
+ buffer, request->buffer_pos, &request->request, http1_on_header_found);
// review result
if (result >= 0) { // headers comeplete
// are we done?
@@ -167,7 +165,7 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
goto parser_error;
// assume incomplete (result == -2), even if wrong, we're right.
pr->len = 0;
- continue;
+ goto postpone;
}
if (request->request.body_file > 0) {
// fprintf(stderr, "Body File\n");
@@ -186,7 +184,7 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
goto finished_reading;
goto parse_body;
}
- continue;
+ goto postpone;
handle_request:
// review required headers / data
if (request->request.host == NULL)
@@ -198,10 +196,10 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
// call request callback
if (pr && settings &&
(request->request.upgrade || settings->public_folder == NULL ||
- http_response_sendfile2(
- NULL, &request->request, settings->public_folder,
- settings->public_folder_length, request->request.path,
- request->request.path_len, settings->log_static))) {
+ http_response_sendfile2(NULL, &request->request, settings->public_folder,
+ settings->public_folder_length,
+ request->request.path, request->request.path_len,
+ settings->log_static))) {
pr->on_request(&request->request);
// fprintf(stderr, "Called on_request\n");
}
@@ -222,18 +220,12 @@ static void http1_on_data(intptr_t uuid, http1_protocol_s *pr) {
request->buffer_pos = pr->len;
// make sure to use the correct buffer.
buffer = request->buffer;
- if (pr->len) {
/* prevent this connection from hogging the thread by pipelining endless
* requests.
*/
+postpone:
facil_force_event(uuid, FIO_EVENT_ON_DATA);
return;
- }
- }
- // no routes lead here.
- fprintf(stderr,
- "I am lost on a deserted island, no code can reach me here :-)\n");
- goto finished_reading; // How did we get here?
parser_error:
if (request->request.headers_count >= HTTP1_MAX_HEADER_COUNT)
goto too_big;
