Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: add maxHeaderSize property #24860

Merged
merged 1 commit into from Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/http.md
Expand Up @@ -1912,6 +1912,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])
## http.request(url[, options][, callback])
<!-- YAML
Expand Down Expand Up @@ -2097,6 +2107,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
Expand Down
14 changes: 14 additions & 0 deletions lib/http.js
Expand Up @@ -32,6 +32,7 @@ const {
Server,
ServerResponse
} = require('_http_server');
let maxHeaderSize;

function createServer(opts, requestListener) {
return new Server(opts, requestListener);
Expand Down Expand Up @@ -62,3 +63,16 @@ module.exports = {
get,
request
};

Object.defineProperty(module.exports, 'maxHeaderSize', {
configurable: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be configurable: false, writeable: false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writable is not supported on accessor descriptors.

enumerable: true,
get() {
if (maxHeaderSize === undefined) {
const { getOptionValue } = require('internal/options');
maxHeaderSize = getOptionValue('--max-http-header-size');
}

return maxHeaderSize;
}
});
11 changes: 11 additions & 0 deletions 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);