summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-21 00:00:43 +0100
committerAnna Henningsen <anna@addaleax.net>2019-12-01 03:00:46 +0100
commit6bf5a1d691291cdfcc4941e68f00d0003e565476 (patch)
tree9cc41f5c66cf6ac67b9392c06619125cc33585e9 /src
parent2205f85b2caadee425a0a86bd8cc3bcb889e4bfe (diff)
downloadandroid-node-v8-6bf5a1d691291cdfcc4941e68f00d0003e565476.tar.gz
android-node-v8-6bf5a1d691291cdfcc4941e68f00d0003e565476.tar.bz2
android-node-v8-6bf5a1d691291cdfcc4941e68f00d0003e565476.zip
http: make maximum header size configurable per-stream or per-server
Make `maxHeaderSize` a.k.a. `--max-header-size` configurable now that the legacy parser is gone (which only supported a single global value). Refs: https://github.com/nodejs/node/pull/30567 PR-URL: https://github.com/nodejs/node/pull/30570 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_http_parser.cc18
-rw-r--r--src/node_options.cc8
-rw-r--r--src/node_options.h2
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;