diff options
author | cjihrig <cjihrig@gmail.com> | 2018-12-05 19:59:12 -0500 |
---|---|---|
committer | Myles Borins <myles.borins@gmail.com> | 2018-12-25 10:08:13 -0500 |
commit | 446f8b54e50f5484aee7faacc6e48f11115b982b (patch) | |
tree | fc049535a92176581a91010baafd9ed1b3054ea6 | |
parent | 693e362175cf50dfa90dff5343a5870dee54ff5f (diff) | |
download | node-new-446f8b54e50f5484aee7faacc6e48f11115b982b.tar.gz |
http: add maxHeaderSize property
This commit exposes the value of --max-http-header-size
as a property of the http module.
Backport-PR-URL: https://github.com/nodejs/node/pull/25218
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>
-rw-r--r-- | doc/api/http.md | 11 | ||||
-rw-r--r-- | lib/http.js | 13 | ||||
-rw-r--r-- | test/parallel/test-http-max-header-size.js | 11 |
3 files changed, 35 insertions, 0 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index 391a2bf423..86ad7d6691 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1805,6 +1805,16 @@ added: v0.5.9 Global instance of `Agent` which is used as the default for all HTTP client 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]) <!-- YAML added: v0.3.6 @@ -1982,6 +1992,7 @@ will be emitted in the following order: Note that setting the `timeout` option or using the `setTimeout` function will 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 [`'request'`]: #http_event_request [`'response'`]: #http_event_response diff --git a/lib/http.js b/lib/http.js index 701a5ccb86..8f68d04e54 100644 --- a/lib/http.js +++ b/lib/http.js @@ -27,6 +27,7 @@ const common = require('_http_common'); const incoming = require('_http_incoming'); const outgoing = require('_http_outgoing'); const server = require('_http_server'); +let maxHeaderSize; const { Server } = server; @@ -59,3 +60,15 @@ module.exports = { get, request }; + +Object.defineProperty(module.exports, 'maxHeaderSize', { + configurable: true, + enumerable: true, + get() { + if (maxHeaderSize === undefined) { + maxHeaderSize = process.binding('config').maxHTTPHeaderSize; + } + + return maxHeaderSize; + } +}); diff --git a/test/parallel/test-http-max-header-size.js b/test/parallel/test-http-max-header-size.js new file mode 100644 index 0000000000..07fbe90296 --- /dev/null +++ b/test/parallel/test-http-max-header-size.js @@ -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); |