diff --git a/deps/http_parser/http_parser.c b/deps/http_parser/http_parser.c index 6522618671d09c..dc77595733a38e 100644 --- a/deps/http_parser/http_parser.c +++ b/deps/http_parser/http_parser.c @@ -150,7 +150,7 @@ do { \ #define COUNT_HEADER_SIZE(V) \ do { \ parser->nread += (V); \ - if (UNLIKELY(parser->nread > (HTTP_MAX_HEADER_SIZE))) { \ + if (UNLIKELY(parser->nread > parser->max_header_size)) { \ SET_ERRNO(HPE_HEADER_OVERFLOW); \ goto error; \ } \ @@ -2105,6 +2105,7 @@ http_parser_init (http_parser *parser, enum http_parser_type t) parser->type = t; parser->state = (t == HTTP_REQUEST ? s_start_req : (t == HTTP_RESPONSE ? s_start_res : s_start_req_or_res)); parser->http_errno = HPE_OK; + parser->max_header_size = HTTP_MAX_HEADER_SIZE; } void diff --git a/deps/http_parser/http_parser.h b/deps/http_parser/http_parser.h index 1fbf30e2b4740b..41a9d741208ef6 100644 --- a/deps/http_parser/http_parser.h +++ b/deps/http_parser/http_parser.h @@ -318,6 +318,8 @@ struct http_parser { /** PUBLIC **/ void *data; /* A pointer to get hook to the "connection" or "socket" object */ + + uint32_t max_header_size; }; diff --git a/lib/_http_common.js b/lib/_http_common.js index 8b68d0c81500a8..12d473af3b8794 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -149,7 +149,7 @@ function parserOnMessageComplete() { const parsers = new FreeList('parsers', 1000, function parsersCb() { - const parser = new HTTPParser(HTTPParser.REQUEST); + const parser = new HTTPParser(HTTPParser.REQUEST, 1024); cleanParser(parser); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 18ac6599d80919..ce02ab151a21b1 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -150,11 +150,12 @@ struct StringPtr { class Parser : public AsyncWrap, public StreamListener { public: - Parser(Environment* env, Local wrap, parser_type_t type) + Parser(Environment* env, Local wrap, parser_type_t type, + uint32_t max_header_size) : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_HTTPPARSER), current_buffer_len_(0), current_buffer_data_(nullptr) { - Init(type); + Init(type, max_header_size); } @@ -423,7 +424,9 @@ class Parser : public AsyncWrap, public StreamListener { parser_type_t type = static_cast(args[0].As()->Value()); CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE); - new Parser(env, args.This(), type); + uint32_t max_header_size = args[1]->IsUint32() ? + args[1].As()->Value(): 0; + new Parser(env, args.This(), type, max_header_size); } @@ -515,7 +518,7 @@ class Parser : public AsyncWrap, public StreamListener { if (isReused) { parser->AsyncReset(); } - parser->Init(type); + parser->Init(type, 1024); } @@ -781,12 +784,14 @@ class Parser : public AsyncWrap, public StreamListener { } - void Init(parser_type_t type) { + void Init(parser_type_t type, uint32_t max_header_size) { #ifdef NODE_EXPERIMENTAL_HTTP llhttp_init(&parser_, type, &settings); header_nread_ = 0; #else /* !NODE_EXPERIMENTAL_HTTP */ http_parser_init(&parser_, type); + parser_.max_header_size = max_header_size; + printf("max_header_size is %d %d\n", max_header_size, parser_.max_header_size); #endif /* NODE_EXPERIMENTAL_HTTP */ url_.Reset(); status_message_.Reset();