http: add maxHeaderSize property

This commit exposes the value of --max-http-header-size
as a property of the http module.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
cjihrig 2018-12-05 19:59:12 -05:00
parent f0e460968e
commit 9ac108d834
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
3 changed files with 36 additions and 0 deletions

View File

@ -1912,6 +1912,16 @@ added: v0.5.9
Global instance of `Agent` which is used as the default for all HTTP client Global instance of `Agent` which is used as the default for all HTTP client
requests. requests.
## http.maxHeaderSize
<!-- YAML
added: REPLACEME
-->
* {number}
Read-only property specifying the maximum allowed size of HTTP headers in bytes.
Defaults to 8KB. Configurable using the [`--max-http-header-size`][] CLI option.
## http.request(options[, callback]) ## http.request(options[, callback])
## http.request(url[, options][, callback]) ## http.request(url[, options][, callback])
<!-- YAML <!-- YAML
@ -2097,6 +2107,7 @@ will be emitted in the following order:
Note that setting the `timeout` option or using the `setTimeout()` function will Note that setting the `timeout` option or using the `setTimeout()` function will
not abort the request or do anything besides add a `'timeout'` event. not abort the request or do anything besides add a `'timeout'` event.
[`--max-http-header-size`]: cli.html#cli_max_http_header_size_size
[`'checkContinue'`]: #http_event_checkcontinue [`'checkContinue'`]: #http_event_checkcontinue
[`'request'`]: #http_event_request [`'request'`]: #http_event_request
[`'response'`]: #http_event_response [`'response'`]: #http_event_response

View File

@ -32,6 +32,7 @@ const {
Server, Server,
ServerResponse ServerResponse
} = require('_http_server'); } = require('_http_server');
let maxHeaderSize;
function createServer(opts, requestListener) { function createServer(opts, requestListener) {
return new Server(opts, requestListener); return new Server(opts, requestListener);
@ -62,3 +63,16 @@ module.exports = {
get, get,
request request
}; };
Object.defineProperty(module.exports, 'maxHeaderSize', {
configurable: true,
enumerable: true,
get() {
if (maxHeaderSize === undefined) {
const { getOptionValue } = require('internal/options');
maxHeaderSize = getOptionValue('--max-http-header-size');
}
return maxHeaderSize;
}
});

View File

@ -0,0 +1,11 @@
'use strict';
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const http = require('http');
assert.strictEqual(http.maxHeaderSize, 8 * 1024);
const child = spawnSync(process.execPath, ['--max-http-header-size=10', '-p',
'http.maxHeaderSize']);
assert.strictEqual(+child.stdout.toString().trim(), 10);