Skip to content

Commit 8cb3456

Browse files
committed
http: make idle http parser count configurable
1 parent 130bdf0 commit 8cb3456

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

doc/api/http.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,6 +3633,16 @@ try {
36333633
}
36343634
```
36353635

3636+
## `http.setMaxIdleHTTPParser`
3637+
3638+
<!-- YAML
3639+
added: REPLACEME
3640+
-->
3641+
3642+
* {number}
3643+
3644+
Set the maximum number of idle HTTP parser,**Default:** `1000`.
3645+
36363646
[RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt
36373647
[`'checkContinue'`]: #event-checkcontinue
36383648
[`'finish'`]: #event-finish

lib/http.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929

3030
const httpAgent = require('_http_agent');
3131
const { ClientRequest } = require('_http_client');
32-
const { methods } = require('_http_common');
32+
const { methods, parsers } = require('_http_common');
3333
const { IncomingMessage } = require('_http_incoming');
3434
const {
3535
validateHeaderName,
@@ -123,7 +123,10 @@ module.exports = {
123123
validateHeaderName,
124124
validateHeaderValue,
125125
get,
126-
request
126+
request,
127+
setMaxIdleHTTPParser(max) {
128+
parsers.updateMax(max);
129+
}
127130
};
128131

129132
ObjectDefineProperty(module.exports, 'maxHeaderSize', {

lib/internal/freelist.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { validateNumber } = require('internal/validators');
4+
35
const {
46
ReflectApply,
57
} = primordials;
@@ -25,6 +27,11 @@ class FreeList {
2527
}
2628
return false;
2729
}
30+
31+
updateMax(max) {
32+
validateNumber(max, 'max');
33+
this.max = max;
34+
}
2835
}
2936

3037
module.exports = FreeList;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const httpCommon = require('_http_common');
5+
const http = require('http');
6+
7+
http.setMaxIdleHTTPParser(1);
8+
assert.strictEqual(httpCommon.parsers.max, 1);

0 commit comments

Comments
 (0)