Skip to content

Commit 0b909a4

Browse files
theanarkhdanielleadams
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 cbc1189 commit 0b909a4

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

doc/api/http.md

Lines changed: 10 additions & 0 deletions
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

Lines 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', {
Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy