From 5b37977e327630243070115e6c783974990af049 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 20 Nov 2009 15:17:20 +0100 Subject: [PATCH] Don't put should_keep_alive messages in front of messages --- http_parser.c | 12 ++++++------ test.c | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/http_parser.c b/http_parser.c index 314b686..7362c24 100644 --- a/http_parser.c +++ b/http_parser.c @@ -1250,19 +1250,19 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state CALLBACK2(headers_complete); if (parser->flags & F_CHUNKED) { - /* chunked encoding - ignore content-lenght header */ + /* chunked encoding - ignore Content-Length header */ state = s_chunk_size_start; } else { if (parser->content_length == 0) { - /* content-length header given, but zero: Content-Length: 0\r\n */ + /* Content-Length header given but zero: Content-Length: 0\r\n */ CALLBACK2(message_complete); state = start_state; } else if (parser->content_length > 0) { - /* content-length header given, and positive */ + /* Content-Length header given and non-zero */ state = s_body_identity; } else { - /* No content-length header, not chunked */ - if (parser->http_major > 0) { + /* No Content-Length header, not chunked */ + if (parser->http_major > 0 && parser->http_minor > 0) { /* HTTP/1.0 or HTTP/1.1 */ if (parser->flags & F_CONNECTION_CLOSE) { /* Read body until EOF */ @@ -1273,7 +1273,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state state = start_state; } } else { - /* HTTP/0.9 or earlier */ + /* HTTP/1.0 or earlier */ if (parser->flags & F_CONNECTION_KEEP_ALIVE) { /* Message is done - read the next */ CALLBACK2(message_complete); diff --git a/test.c b/test.c index 5f5a6d0..62fe943 100644 --- a/test.c +++ b/test.c @@ -854,7 +854,11 @@ test_multiple3 (const struct message *r1, const struct message *r2, const struct exit(1); } - assert(num_messages == 3); + if (3 != num_messages) { + fprintf(stderr, "\n\n*** Parser didn't see 3 messages only %d *** \n", num_messages); + exit(1); + } + if (!message_eq(0, r1)) exit(1); if (!message_eq(1, r2)) exit(1); if (!message_eq(2, r3)) exit(1); @@ -980,6 +984,16 @@ main (void) test_message(&responses[i]); } + for (i = 0; i < response_count; i++) { + if (!responses[i].should_keep_alive) continue; + for (j = 0; j < response_count; j++) { + if (!responses[j].should_keep_alive) continue; + for (k = 0; k < response_count; k++) { + test_multiple3(&responses[i], &responses[j], &responses[k]); + } + } + } + printf("response scan 1/1 "); test_scan( &responses[TRAILING_SPACE_ON_CHUNKED_BODY] , &responses[NO_HEADERS_NO_BODY_404] @@ -1055,7 +1069,9 @@ main (void) for (i = 0; i < request_count; i++) { + if (!requests[i].should_keep_alive) continue; for (j = 0; j < request_count; j++) { + if (!requests[j].should_keep_alive) continue; for (k = 0; k < request_count; k++) { test_multiple3(&requests[i], &requests[j], &requests[k]); }