diff --git a/doc/api/http.md b/doc/api/http.md index 08bb937e4c92a4..be023f7bc22965 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3633,6 +3633,16 @@ try { } ``` +## `http.setMaxIdleHTTPParsers` + + + +* {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 diff --git a/lib/http.js b/lib/http.js index 1366656e42eb94..d6d198bb587876 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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, @@ -123,7 +124,11 @@ module.exports = { validateHeaderName, validateHeaderValue, get, - request + request, + setMaxIdleHTTPParsers(max) { + validateInteger(max, 'max'); + parsers.max = max; + } }; ObjectDefineProperty(module.exports, 'maxHeaderSize', { diff --git a/test/parallel/test-http-set-max-idle-http-parser.js b/test/parallel/test-http-set-max-idle-http-parser.js new file mode 100644 index 00000000000000..0413152ce22135 --- /dev/null +++ b/test/parallel/test-http-set-max-idle-http-parser.js @@ -0,0 +1,8 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const httpCommon = require('_http_common'); +const http = require('http'); +assert.strictEqual(httpCommon.parsers.max !== 1, true); +http.setMaxIdleHTTPParsers(1); +assert.strictEqual(httpCommon.parsers.max, 1);