Skip to content

Commit a2cd8b3

Browse files
theanarkhruyadorno
authored andcommitted
http: make idle http parser count configurable
PR-URL: #43974 Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Feng Yu <[email protected]>
1 parent b19564b commit a2cd8b3

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

doc/api/http.md

+10
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,16 @@ try {
36153615
}
36163616
```
36173617

3618+
## `http.setMaxIdleHTTPParsers`
3619+
3620+
<!-- YAML
3621+
added: REPLACEME
3622+
-->
3623+
3624+
* {number}
3625+
3626+
Set the maximum number of idle HTTP parsers. **Default:** `1000`.
3627+
36183628
[RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt
36193629
[`'checkContinue'`]: #event-checkcontinue
36203630
[`'finish'`]: #event-finish

lib/http.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ const {
2727
ObjectDefineProperty,
2828
} = primordials;
2929

30+
const { validateInteger } = require('internal/validators');
3031
const httpAgent = require('_http_agent');
3132
const { ClientRequest } = require('_http_client');
32-
const { methods } = require('_http_common');
33+
const { methods, parsers } = require('_http_common');
3334
const { IncomingMessage } = require('_http_incoming');
3435
const {
3536
validateHeaderName,
@@ -123,7 +124,11 @@ module.exports = {
123124
validateHeaderName,
124125
validateHeaderValue,
125126
get,
126-
request
127+
request,
128+
setMaxIdleHTTPParsers(max) {
129+
validateInteger(max, 'max', 1);
130+
parsers.max = max;
131+
}
127132
};
128133

129134
ObjectDefineProperty(module.exports, 'maxHeaderSize', {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const httpCommon = require('_http_common');
5+
const http = require('http');
6+
7+
[Symbol(), {}, [], () => {}, 1n, true, '1', null, undefined].forEach((value) => {
8+
assert.throws(() => http.setMaxIdleHTTPParsers(value), { code: 'ERR_INVALID_ARG_TYPE' });
9+
});
10+
11+
[-1, -Infinity, NaN, 0, 1.1].forEach((value) => {
12+
assert.throws(() => http.setMaxIdleHTTPParsers(value), { code: 'ERR_OUT_OF_RANGE' });
13+
});
14+
15+
[1, Number.MAX_SAFE_INTEGER].forEach((value) => {
16+
assert.notStrictEqual(httpCommon.parsers.max, value);
17+
http.setMaxIdleHTTPParsers(value);
18+
assert.strictEqual(httpCommon.parsers.max, value);
19+
});

0 commit comments

Comments
 (0)