Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2cd8b3

Browse filesBrowse files
theanarkhruyadorno
authored andcommitted
http: make idle http parser count configurable
PR-URL: #43974 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent b19564b commit a2cd8b3
Copy full SHA for a2cd8b3

File tree

Expand file treeCollapse file tree

3 files changed

+36
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+36
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/http.md‎

Copy file name to clipboardExpand all lines: doc/api/http.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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
Collapse file

‎lib/http.js‎

Copy file name to clipboardExpand all lines: lib/http.js
+7-2Lines changed: 7 additions & 2 deletions
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', {
Collapse file
+19Lines changed: 19 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.