Skip to content

Commit 446f8b5

Browse files
cjihrigMylesBorins
authored andcommittedDec 25, 2018
http: add maxHeaderSize property
This commit exposes the value of --max-http-header-size as a property of the http module. Backport-PR-URL: #25218 PR-URL: #24860 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 693e362 commit 446f8b5

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
 

‎doc/api/http.md

+11
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,16 @@ added: v0.5.9
18051805
Global instance of `Agent` which is used as the default for all HTTP client
18061806
requests.
18071807

1808+
## http.maxHeaderSize
1809+
<!-- YAML
1810+
added: REPLACEME
1811+
-->
1812+
1813+
* {number}
1814+
1815+
Read-only property specifying the maximum allowed size of HTTP headers in bytes.
1816+
Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option.
1817+
18081818
## http.request(options[, callback])
18091819
<!-- YAML
18101820
added: v0.3.6
@@ -1982,6 +1992,7 @@ will be emitted in the following order:
19821992
Note that setting the `timeout` option or using the `setTimeout` function will
19831993
not abort the request or do anything besides add a `timeout` event.
19841994

1995+
[`--max-http-header-size`]: cli.html#cli_max_http_header_size_size
19851996
[`'checkContinue'`]: #http_event_checkcontinue
19861997
[`'request'`]: #http_event_request
19871998
[`'response'`]: #http_event_response

‎lib/http.js

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const common = require('_http_common');
2727
const incoming = require('_http_incoming');
2828
const outgoing = require('_http_outgoing');
2929
const server = require('_http_server');
30+
let maxHeaderSize;
3031

3132
const { Server } = server;
3233

@@ -59,3 +60,15 @@ module.exports = {
5960
get,
6061
request
6162
};
63+
64+
Object.defineProperty(module.exports, 'maxHeaderSize', {
65+
configurable: true,
66+
enumerable: true,
67+
get() {
68+
if (maxHeaderSize === undefined) {
69+
maxHeaderSize = process.binding('config').maxHTTPHeaderSize;
70+
}
71+
72+
return maxHeaderSize;
73+
}
74+
});
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { spawnSync } = require('child_process');
6+
const http = require('http');
7+
8+
assert.strictEqual(http.maxHeaderSize, 8 * 1024);
9+
const child = spawnSync(process.execPath, ['--max-http-header-size=10', '-p',
10+
'http.maxHeaderSize']);
11+
assert.strictEqual(+child.stdout.toString().trim(), 10);

0 commit comments

Comments
 (0)
Please sign in to comment.