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: make idle http parser count configurable #43974

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -3633,6 +3633,16 @@ try {
}
```

## `http.setMaxIdleHTTPParsers`

<!-- YAML
added: REPLACEME
-->

* {number}

Set the maximum number of idle HTTP parsers. **Default:** `1000`.

[RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt
[`'checkContinue'`]: #event-checkcontinue
[`'finish'`]: #event-finish
Expand Down
9 changes: 7 additions & 2 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const {
ObjectDefineProperty,
} = primordials;

const { validateInteger } = require('internal/validators');
const httpAgent = require('_http_agent');
const { ClientRequest } = require('_http_client');
const { methods } = require('_http_common');
const { methods, parsers } = require('_http_common');
const { IncomingMessage } = require('_http_incoming');
const {
validateHeaderName,
Expand Down Expand Up @@ -123,7 +124,11 @@ module.exports = {
validateHeaderName,
validateHeaderValue,
get,
request
request,
setMaxIdleHTTPParsers(max) {
validateInteger(max, 'max', 1);
parsers.max = max;
}
};

ObjectDefineProperty(module.exports, 'maxHeaderSize', {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-http-set-max-idle-http-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
require('../common');
const assert = require('assert');
const httpCommon = require('_http_common');
const http = require('http');

theanarkh marked this conversation as resolved.
Show resolved Hide resolved
[Symbol(), {}, [], () => {}, 1n, true, '1', null, undefined].forEach((value) => {
assert.throws(() => http.setMaxIdleHTTPParsers(value), { code: 'ERR_INVALID_ARG_TYPE' });
});

[-1, -Infinity, NaN, 0, 1.1].forEach((value) => {
assert.throws(() => http.setMaxIdleHTTPParsers(value), { code: 'ERR_OUT_OF_RANGE' });
});

[1, Number.MAX_SAFE_INTEGER].forEach((value) => {
assert.notStrictEqual(httpCommon.parsers.max, value);
http.setMaxIdleHTTPParsers(value);
assert.strictEqual(httpCommon.parsers.max, value);
});