From 873912df5e88f8c4a93026055e8e1607f00c7f11 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 21 Nov 2009 17:08:40 +0100 Subject: [PATCH] Only use s_dead in STRICT mode. --- http_parser.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/http_parser.c b/http_parser.c index 34ed461..fb50157 100644 --- a/http_parser.c +++ b/http_parser.c @@ -258,8 +258,10 @@ enum flags #if HTTP_PARSER_STRICT # define STRICT_CHECK(cond) if (cond) return ERROR +# define NEW_MESSAGE() (http_should_keep_alive(parser) ? start_state : s_dead) #else # define STRICT_CHECK(cond) +# define NEW_MESSAGE() start_state #endif static inline @@ -295,7 +297,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state /* this state is used after a 'Connection: close' message * the parser will error out if it reads another message */ - return 0; + return ERROR; case s_start_res: { @@ -1249,7 +1251,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state if (parser->flags & F_TRAILING) { /* End of a chunked request */ CALLBACK2(message_complete); - state = http_should_keep_alive(parser) ? start_state : s_dead; + state = NEW_MESSAGE(); break; } @@ -1264,7 +1266,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state if (parser->content_length == 0) { /* Content-Length header given but zero: Content-Length: 0\r\n */ CALLBACK2(message_complete); - state = http_should_keep_alive(parser) ? start_state : s_dead; + state = NEW_MESSAGE(); } else if (parser->content_length > 0) { /* Content-Length header given and non-zero */ state = s_body_identity; @@ -1272,7 +1274,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state if (start_state == s_start_req || http_should_keep_alive(parser)) { /* Assume content-length 0 - read the next */ CALLBACK2(message_complete); - state = start_state; + state = NEW_MESSAGE(); } else { /* Read body until EOF */ state = s_body_identity_eof; @@ -1291,7 +1293,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state parser->body_read += to_read; if (parser->body_read == parser->content_length) { CALLBACK2(message_complete); - state = http_should_keep_alive(parser) ? start_state : s_dead; + state = NEW_MESSAGE(); } } break;