diff options
Diffstat (limited to 'src/node_http_parser.cc')
-rw-r--r-- | src/node_http_parser.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index c6136702c7..0328dc7c0f 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -62,6 +62,7 @@ using v8::Int32; using v8::Integer; using v8::Local; using v8::MaybeLocal; +using v8::Number; using v8::Object; using v8::String; using v8::Uint32; @@ -486,8 +487,17 @@ class Parser : public AsyncWrap, public StreamListener { static void Initialize(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); + uint64_t max_http_header_size = 0; + CHECK(args[0]->IsInt32()); CHECK(args[1]->IsObject()); + if (args.Length() > 2) { + CHECK(args[2]->IsNumber()); + max_http_header_size = args[2].As<Number>()->Value(); + } + if (max_http_header_size == 0) { + max_http_header_size = env->options()->max_http_header_size; + } llhttp_type_t type = static_cast<llhttp_type_t>(args[0].As<Int32>()->Value()); @@ -505,7 +515,7 @@ class Parser : public AsyncWrap, public StreamListener { parser->set_provider_type(provider); parser->AsyncReset(args[1].As<Object>()); - parser->Init(type); + parser->Init(type, max_http_header_size); } template <bool should_pause> @@ -752,7 +762,7 @@ class Parser : public AsyncWrap, public StreamListener { } - void Init(llhttp_type_t type) { + void Init(llhttp_type_t type, uint64_t max_http_header_size) { llhttp_init(&parser_, type, &settings); header_nread_ = 0; url_.Reset(); @@ -761,12 +771,13 @@ class Parser : public AsyncWrap, public StreamListener { num_values_ = 0; have_flushed_ = false; got_exception_ = false; + max_http_header_size_ = max_http_header_size; } int TrackHeader(size_t len) { header_nread_ += len; - if (header_nread_ >= per_process::cli_options->max_http_header_size) { + if (header_nread_ >= max_http_header_size_) { llhttp_set_error_reason(&parser_, "HPE_HEADER_OVERFLOW:Header overflow"); return HPE_USER; } @@ -801,6 +812,7 @@ class Parser : public AsyncWrap, public StreamListener { unsigned int execute_depth_ = 0; bool pending_pause_ = false; uint64_t header_nread_ = 0; + uint64_t max_http_header_size_; // These are helper functions for filling `http_parser_settings`, which turn // a member function of Parser into a C-style HTTP parser callback. |