diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/node_http_parser.cc | 18 | ||||
-rw-r--r-- | src/node_options.cc | 8 | ||||
-rw-r--r-- | src/node_options.h | 2 |
3 files changed, 20 insertions, 8 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. diff --git a/src/node_options.cc b/src/node_options.cc index 44b125775f..498bedd1e5 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -440,6 +440,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "profile generated with --heap-prof. (default: 512 * 1024)", &EnvironmentOptions::heap_prof_interval); #endif // HAVE_INSPECTOR + AddOption("--max-http-header-size", + "set the maximum size of HTTP headers (default: 8192 (8KB))", + &EnvironmentOptions::max_http_header_size, + kAllowedInEnvironment); AddOption("--redirect-warnings", "write warnings to file instead of stderr", &EnvironmentOptions::redirect_warnings, @@ -632,10 +636,6 @@ PerProcessOptionsParser::PerProcessOptionsParser( kAllowedInEnvironment); AddAlias("--trace-events-enabled", { "--trace-event-categories", "v8,node,node.async_hooks" }); - AddOption("--max-http-header-size", - "set the maximum size of HTTP headers (default: 8KB)", - &PerProcessOptions::max_http_header_size, - kAllowedInEnvironment); AddOption("--v8-pool-size", "set V8's thread pool size", &PerProcessOptions::v8_thread_pool_size, diff --git a/src/node_options.h b/src/node_options.h index adc0ef783f..fea912da44 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -115,6 +115,7 @@ class EnvironmentOptions : public Options { bool expose_internals = false; bool frozen_intrinsics = false; std::string heap_snapshot_signal; + uint64_t max_http_header_size = 8 * 1024; bool no_deprecation = false; bool no_force_async_hooks_checks = false; bool no_warnings = false; @@ -201,7 +202,6 @@ class PerProcessOptions : public Options { std::string title; std::string trace_event_categories; std::string trace_event_file_pattern = "node_trace.${rotation}.log"; - uint64_t max_http_header_size = 8 * 1024; int64_t v8_thread_pool_size = 4; bool zero_fill_all_buffers = false; bool debug_arraybuffer_allocations = false; |