diff --git a/deps/http_parser/http_parser.c b/deps/http_parser/http_parser.c index c600ff19b2..02532d3a2c 100644 --- a/deps/http_parser/http_parser.c +++ b/deps/http_parser/http_parser.c @@ -108,7 +108,7 @@ static const char *method_strings[] = /* ' ', '_', '-' and all alpha-numeric ascii characters are accepted by acceptable_header. The 'A'-'Z' are lower-cased. */ -static const unsigned char acceptable_header[256] = { +static const char acceptable_header[256] = { /* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ 0, 0, 0, 0, 0, 0, 0, 0, /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ @@ -143,7 +143,7 @@ static const unsigned char acceptable_header[256] = { 'x', 'y', 'z', 0, 0, 0, 0, 0 }; -static const int unhex[256] = +static const int8_t unhex[256] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 @@ -155,7 +155,7 @@ static const int unhex[256] = }; -static const int normal_url_char[256] = { +static const uint8_t normal_url_char[256] = { /* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ 0, 0, 0, 0, 0, 0, 0, 0, /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ @@ -600,7 +600,7 @@ size_t http_parser_execute (http_parser *parser, if (ch == ' ' && matcher[index] == '\0') { state = s_req_spaces_before_url; } else if (ch == matcher[index]) { - ; // nada + ; /* nada */ } else if (parser->method == HTTP_CONNECT) { if (index == 1 && ch == 'H') { parser->method = HTTP_CHECKOUT; @@ -772,7 +772,7 @@ size_t http_parser_execute (http_parser *parser, switch (ch) { case '?': - break; // XXX ignore extra '?' ... is this right? + break; /* XXX ignore extra '?' ... is this right? */ case ' ': CALLBACK(url); state = s_req_http_start; @@ -802,7 +802,7 @@ size_t http_parser_execute (http_parser *parser, switch (ch) { case '?': - // allow extra '?' in query string + /* allow extra '?' in query string */ break; case ' ': CALLBACK(url); @@ -1264,6 +1264,7 @@ size_t http_parser_execute (http_parser *parser, break; case h_content_length: + if (ch == ' ') break; if (ch < '0' || ch > '9') goto error; parser->content_length *= 10; parser->content_length += ch - '0'; @@ -1376,7 +1377,7 @@ size_t http_parser_execute (http_parser *parser, } } - // Exit, the rest of the connect is in a different protocol. + /* Exit, the rest of the connect is in a different protocol. */ if (parser->upgrade) { CALLBACK2(message_complete); return (p - data); @@ -1437,7 +1438,7 @@ size_t http_parser_execute (http_parser *parser, { assert(parser->flags & F_CHUNKED); - c = unhex[(int)ch]; + c = unhex[(unsigned char)ch]; if (c == -1) goto error; parser->content_length = c; state = s_chunk_size; @@ -1453,7 +1454,7 @@ size_t http_parser_execute (http_parser *parser, break; } - c = unhex[(int)ch]; + c = unhex[(unsigned char)ch]; if (c == -1) { if (ch == ';' || ch == ' ') { @@ -1545,6 +1546,7 @@ size_t http_parser_execute (http_parser *parser, return len; error: + parser->state = s_dead; return (p - data); } diff --git a/deps/http_parser/http_parser.h b/deps/http_parser/http_parser.h index 2e395a24e9..793089a67d 100644 --- a/deps/http_parser/http_parser.h +++ b/deps/http_parser/http_parser.h @@ -100,14 +100,13 @@ enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH }; struct http_parser { /** PRIVATE **/ - unsigned char type; + unsigned char type : 2; + unsigned char flags : 6; unsigned char state; unsigned char header_state; unsigned char index; - char flags; - - uint64_t nread; + uint32_t nread; int64_t content_length; /** READ-ONLY **/ diff --git a/test/simple/test-http-contentLength0.js b/test/simple/test-http-contentLength0.js new file mode 100644 index 0000000000..7e3dca5409 --- /dev/null +++ b/test/simple/test-http-contentLength0.js @@ -0,0 +1,23 @@ +var common = require('../common'); +var http = require("http"); + +// Simple test of Node's HTTP Client choking on a response with a "Content-Length: 0 " response header. +// I.E. a space character after the "Content-Length" throws an `error` event. + + +var s = http.createServer(function(req, res) { + res.writeHead(200, { "Content-Length": "0 " }); + res.end(); +}); +s.listen(common.PORT, function() { + + var r = http.createClient(common.PORT); + var request = r.request('GET', '/'); + + request.on('response', function (response) { + console.log('STATUS: ' + response.statusCode); + s.close(); + }); + + request.end(); +});