Skip to content

Commit c0c4de7

Browse files
cjihrigMylesBorins
authored andcommitted
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 f233b16 commit c0c4de7

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

doc/api/http.md

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

1584+
## http.maxHeaderSize
1585+
<!-- YAML
1586+
added: REPLACEME
1587+
-->
1588+
1589+
* {number}
1590+
1591+
Read-only property specifying the maximum allowed size of HTTP headers in bytes.
1592+
Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option.
1593+
15841594
## http.request(options[, callback])
15851595
<!-- YAML
15861596
added: v0.3.6
@@ -1698,6 +1708,7 @@ There are a few special headers that should be noted.
16981708
* Sending an Authorization header will override using the `auth` option
16991709
to compute basic authentication.
17001710

1711+
[`--max-http-header-size`]: cli.html#cli_max_http_header_size_size
17011712
[`'checkContinue'`]: #http_event_checkcontinue
17021713
[`'listening'`]: net.html#net_event_listening
17031714
[`'request'`]: #http_event_request

lib/http.js

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const server = require('_http_server');
1919
exports.ServerResponse = server.ServerResponse;
2020
exports.STATUS_CODES = server.STATUS_CODES;
2121

22+
let maxHeaderSize;
23+
2224

2325
const agent = require('_http_agent');
2426
const Agent = exports.Agent = agent.Agent;
@@ -92,8 +94,21 @@ Client.prototype.request = function(method, path, headers) {
9294
return c;
9395
};
9496

97+
9598
exports.Client = internalUtil.deprecate(Client, 'http.Client is deprecated.');
9699

97100
exports.createClient = internalUtil.deprecate(function(port, host) {
98101
return new Client(port, host);
99102
}, 'http.createClient is deprecated. Use http.request instead.');
103+
104+
Object.defineProperty(module.exports, 'maxHeaderSize', {
105+
configurable: true,
106+
enumerable: true,
107+
get() {
108+
if (maxHeaderSize === undefined) {
109+
maxHeaderSize = process.binding('config').maxHTTPHeaderSize;
110+
}
111+
112+
return maxHeaderSize;
113+
}
114+
});
+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)