Skip to content

Commit 8398e98

Browse files
theanarkhjuanarbol
authored andcommittedOct 11, 2022
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 092239a commit 8398e98

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
@@ -3557,6 +3557,16 @@ try {
35573557
}
35583558
```
35593559

3560+
## `http.setMaxIdleHTTPParsers`
3561+
3562+
<!-- YAML
3563+
added: REPLACEME
3564+
-->
3565+
3566+
* {number}
3567+
3568+
Set the maximum number of idle HTTP parsers. **Default:** `1000`.
3569+
35603570
[RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt
35613571
[`'checkContinue'`]: #event-checkcontinue
35623572
[`'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)
Please sign in to comment.