Skip to content

Commit

Permalink
http: make idle http parser count configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Jul 25, 2022
1 parent 130bdf0 commit b9b00e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -3633,6 +3633,16 @@ try {
}
```

## `http.setMaxIdleHTTPParsers`

<!-- YAML
added: REPLACEME
-->

* {number}

Set the maximum number of idle HTTP parsers. **Default:** `1000`.

[RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt
[`'checkContinue'`]: #event-checkcontinue
[`'finish'`]: #event-finish
Expand Down
9 changes: 7 additions & 2 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const {
ObjectDefineProperty,
} = primordials;

const { validateInteger } = require('internal/validators');
const httpAgent = require('_http_agent');
const { ClientRequest } = require('_http_client');
const { methods } = require('_http_common');
const { methods, parsers } = require('_http_common');
const { IncomingMessage } = require('_http_incoming');
const {
validateHeaderName,
Expand Down Expand Up @@ -123,7 +124,11 @@ module.exports = {
validateHeaderName,
validateHeaderValue,
get,
request
request,
setMaxIdleHTTPParsers(max) {
validateInteger(max, 'max');
parsers.max = max;
}
};

ObjectDefineProperty(module.exports, 'maxHeaderSize', {
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-http-set-max-idle-http-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
require('../common');
const assert = require('assert');
const httpCommon = require('_http_common');
const http = require('http');
assert(httpCommon.parsers.max !== 1);
http.setMaxIdleHTTPParsers(1);
assert.strictEqual(httpCommon.parsers.max, 1);

0 comments on commit b9b00e2

Please sign in to comment.