Skip to content

Commit

Permalink
http: add maxHeaderSize property
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Shelley Vohr <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Dec 25, 2018
1 parent f233b16 commit c0c4de7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,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
Expand Down Expand Up @@ -1698,6 +1708,7 @@ There are a few special headers that should be noted.
* Sending an Authorization header will override using the `auth` option
to compute basic authentication.

[`--max-http-header-size`]: cli.html#cli_max_http_header_size_size
[`'checkContinue'`]: #http_event_checkcontinue
[`'listening'`]: net.html#net_event_listening
[`'request'`]: #http_event_request
Expand Down
15 changes: 15 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const server = require('_http_server');
exports.ServerResponse = server.ServerResponse;
exports.STATUS_CODES = server.STATUS_CODES;

let maxHeaderSize;


const agent = require('_http_agent');
const Agent = exports.Agent = agent.Agent;
Expand Down Expand Up @@ -92,8 +94,21 @@ Client.prototype.request = function(method, path, headers) {
return c;
};


exports.Client = internalUtil.deprecate(Client, 'http.Client is deprecated.');

exports.createClient = internalUtil.deprecate(function(port, host) {
return new Client(port, host);
}, 'http.createClient is deprecated. Use http.request instead.');

Object.defineProperty(module.exports, 'maxHeaderSize', {
configurable: true,
enumerable: true,
get() {
if (maxHeaderSize === undefined) {
maxHeaderSize = process.binding('config').maxHTTPHeaderSize;
}

return maxHeaderSize;
}
});
11 changes: 11 additions & 0 deletions test/parallel/test-http-max-header-size.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit c0c4de7

Please sign in to comment.