http: make idle http parser count configurable

PR-URL: https://github.com/nodejs/node/pull/43974
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
pull/44039/head
theanarkh 2022-07-29 17:00:38 +08:00 committed by GitHub
parent 447635b440
commit 20e372c242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View File

@ -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

View File

@ -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,
@ -123,7 +124,11 @@ module.exports = {
validateHeaderName,
validateHeaderValue,
get,
request
request,
setMaxIdleHTTPParsers(max) {
validateInteger(max, 'max', 1);
parsers.max = max;
}
};
ObjectDefineProperty(module.exports, 'maxHeaderSize', {

View File

@ -0,0 +1,19 @@
'use strict';
require('../common');
const assert = require('assert');
const httpCommon = require('_http_common');
const http = require('http');
[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);
});