diff --git a/deps/http_parser/http_parser.c b/deps/http_parser/http_parser.c index 834c5b2537..ac1b9d6fbf 100644 --- a/deps/http_parser/http_parser.c +++ b/deps/http_parser/http_parser.c @@ -111,7 +111,7 @@ static const char *method_strings[] = static const char lowcase[256] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0\0\0\0\0\0-\0\0" "0123456789\0\0\0\0\0\0" + " \0\0\0\0\0\0\0\0\0\0\0\0-\0\0" "0123456789\0\0\0\0\0\0" "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0_" "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -287,12 +287,12 @@ size_t http_parser_execute (http_parser *parser, { char c, ch; const char *p = data, *pe; - ssize_t to_read; + int64_t to_read; enum state state = (enum state) parser->state; enum header_states header_state = (enum header_states) parser->header_state; - size_t index = parser->index; - size_t nread = parser->nread; + uint64_t index = parser->index; + uint64_t nread = parser->nread; if (len == 0) { if (state == s_body_identity_eof) { @@ -1316,7 +1316,9 @@ size_t http_parser_execute (http_parser *parser, nread = 0; - if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) parser->upgrade = 1; + if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) { + parser->upgrade = 1; + } /* Here we call the headers_complete callback. This is somewhat * different than other callbacks because if the user returns 1, we @@ -1339,7 +1341,7 @@ size_t http_parser_execute (http_parser *parser, } // Exit, the rest of the connect is in a different protocol. - if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) { + if (parser->upgrade) { CALLBACK2(message_complete); return (p - data); } @@ -1374,7 +1376,7 @@ size_t http_parser_execute (http_parser *parser, } case s_body_identity: - to_read = MIN(pe - p, (ssize_t)parser->content_length); + to_read = MIN(pe - p, (int64_t)parser->content_length); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; @@ -1459,7 +1461,7 @@ size_t http_parser_execute (http_parser *parser, { assert(parser->flags & F_CHUNKED); - to_read = MIN(pe - p, (ssize_t)(parser->content_length)); + to_read = MIN(pe - p, (int64_t)(parser->content_length)); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); diff --git a/deps/http_parser/http_parser.h b/deps/http_parser/http_parser.h index f019985e53..2e395a24e9 100644 --- a/deps/http_parser/http_parser.h +++ b/deps/http_parser/http_parser.h @@ -26,6 +26,7 @@ extern "C" { #include +#include #ifdef _WIN32 typedef unsigned int size_t; @@ -106,8 +107,8 @@ struct http_parser { char flags; - size_t nread; - ssize_t content_length; + uint64_t nread; + int64_t content_length; /** READ-ONLY **/ unsigned short http_major; diff --git a/deps/http_parser/test.c b/deps/http_parser/test.c index 864b289545..6971217296 100644 --- a/deps/http_parser/test.c +++ b/deps/http_parser/test.c @@ -801,6 +801,38 @@ const struct message responses[] = ,.body= "" } +#define SPACE_IN_FIELD_RES 9 +/* Should handle spaces in header fields */ +, {.name= "field space" + ,.type= HTTP_RESPONSE + ,.raw= "HTTP/1.1 200 OK\r\n" + "Server: Microsoft-IIS/6.0\r\n" + "X-Powered-By: ASP.NET\r\n" + "en-US Content-Type: text/xml\r\n" /* this is the problem */ + "Content-Type: text/xml\r\n" + "Content-Length: 16\r\n" + "Date: Fri, 23 Jul 2010 18:45:38 GMT\r\n" + "Connection: keep-alive\r\n" + "\r\n" + "hello" /* fake body */ + ,.should_keep_alive= TRUE + ,.message_complete_on_eof= FALSE + ,.http_major= 1 + ,.http_minor= 1 + ,.status_code= 200 + ,.num_headers= 7 + ,.headers= + { { "Server", "Microsoft-IIS/6.0" } + , { "X-Powered-By", "ASP.NET" } + , { "en-US Content-Type", "text/xml" } + , { "Content-Type", "text/xml" } + , { "Content-Length", "16" } + , { "Date", "Fri, 23 Jul 2010 18:45:38 GMT" } + , { "Connection", "keep-alive" } + } + ,.body= "hello" + } + , {.name= NULL } /* sentinel */ }; @@ -1581,7 +1613,7 @@ main (void) , &responses[NO_REASON_PHRASE] ); - printf("response scan 1/2 "); + printf("response scan 2/2 "); test_scan( &responses[BONJOUR_MADAME_FR] , &responses[UNDERSTORE_HEADER_KEY] , &responses[NO_CARRIAGE_RET]