Skip to content

Commit

Permalink
fixup! http: make maximum header size configurable per-stream or per-…
Browse files Browse the repository at this point in the history
…server
  • Loading branch information
addaleax committed Nov 30, 2019
1 parent a92936a commit 65d8813
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const {
ERR_INVALID_PROTOCOL,
ERR_UNESCAPED_CHARACTERS
} = codes;
const { validateInteger } = require('internal/validators');
const { getTimerDuration } = require('internal/timers');
const {
DTRACE_HTTP_CLIENT_REQUEST,
Expand Down Expand Up @@ -178,10 +179,8 @@ function ClientRequest(input, options, cb) {
}

const maxHeaderSize = options.maxHeaderSize;
if (maxHeaderSize !== undefined && (!Number.isSafeInteger(maxHeaderSize) ||
maxHeaderSize < 0)) {
throw new ERR_INVALID_ARG_TYPE('maxHeaderSize', 'number', maxHeaderSize);
}
if (maxHeaderSize !== undefined)
validateInteger(maxHeaderSize, 'maxHeaderSize', 0);
this.maxHeaderSize = maxHeaderSize;

this.path = options.path || '/';
Expand Down
7 changes: 3 additions & 4 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CHAR
} = require('internal/errors').codes;
const { validateInteger } = require('internal/validators');
const Buffer = require('buffer').Buffer;
const {
DTRACE_HTTP_SERVER_REQUEST,
Expand Down Expand Up @@ -323,10 +324,8 @@ function Server(options, requestListener) {
this[kServerResponse] = options.ServerResponse || ServerResponse;

const maxHeaderSize = options.maxHeaderSize;
if (maxHeaderSize !== undefined && (!Number.isSafeInteger(maxHeaderSize) ||
maxHeaderSize < 0)) {
throw new ERR_INVALID_ARG_TYPE('maxHeaderSize', 'number', maxHeaderSize);
}
if (maxHeaderSize !== undefined)
validateInteger(maxHeaderSize, 'maxHeaderSize', 0);
this.maxHeaderSize = maxHeaderSize;

net.Server.call(this, { allowHalfOpen: true });
Expand Down
2 changes: 1 addition & 1 deletion src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"profile generated with --heap-prof. (default: 512 * 1024)",
&EnvironmentOptions::heap_prof_interval);
AddOption("--max-http-header-size",
"set the maximum size of HTTP headers (default: 8KB)",
"set the maximum size of HTTP headers (default: 8192 (8KB))",
&EnvironmentOptions::max_http_header_size,
kAllowedInEnvironment);
#endif // HAVE_INSPECTOR
Expand Down

0 comments on commit 65d8813

Please sign in to comment.