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 24, 2022
1 parent 130bdf0 commit 8cb3456
Show file tree
Hide file tree
Showing 4 changed files with 30 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.setMaxIdleHTTPParser`

<!-- YAML
added: REPLACEME
-->

* {number}

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

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

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 +123,10 @@ module.exports = {
validateHeaderName,
validateHeaderValue,
get,
request
request,
setMaxIdleHTTPParser(max) {
parsers.updateMax(max);
}
};

ObjectDefineProperty(module.exports, 'maxHeaderSize', {
Expand Down
7 changes: 7 additions & 0 deletions lib/internal/freelist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { validateNumber } = require('internal/validators');

const {
ReflectApply,
} = primordials;
Expand All @@ -25,6 +27,11 @@ class FreeList {
}
return false;
}

updateMax(max) {
validateNumber(max, 'max');
this.max = max;
}
}

module.exports = FreeList;
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');

http.setMaxIdleHTTPParser(1);
assert.strictEqual(httpCommon.parsers.max, 1);

0 comments on commit 8cb3456

Please sign in to comment.