Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 851264c

Browse filesBrowse files
theanarkhruyadorno
authored andcommitted
http: add max for http keepalive
PR-URL: #44217 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent c842ab3 commit 851264c
Copy full SHA for 851264c

File tree

Expand file treeCollapse file tree

4 files changed

+9
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+9
-4
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,11 @@ function _storeHeader(firstLine, headers) {
463463
header += 'Connection: keep-alive\r\n';
464464
if (this._keepAliveTimeout && this._defaultKeepAlive) {
465465
const timeoutSeconds = MathFloor(this._keepAliveTimeout / 1000);
466-
header += `Keep-Alive: timeout=${timeoutSeconds}\r\n`;
466+
let max = '';
467+
if (~~this._maxRequestsPerSocket > 0) {
468+
max = `, max=${this._maxRequestsPerSocket}`;
469+
}
470+
header += `Keep-Alive: timeout=${timeoutSeconds}${max}\r\n`;
467471
}
468472
} else {
469473
this._last = true;
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
959959

960960
const res = new server[kServerResponse](req);
961961
res._keepAliveTimeout = server.keepAliveTimeout;
962+
res._maxRequestsPerSocket = server.maxRequestsPerSocket;
962963
res._onPendingData = updateOutgoingData.bind(undefined,
963964
socket, state);
964965

Collapse file

‎test/parallel/test-http-keep-alive-max-requests.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-keep-alive-max-requests.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function assertResponse(headers, body, expectClosed) {
1414
assert.match(body, /Hello World!/m);
1515
} else {
1616
assert.match(headers, /Connection: keep-alive\r\n/m);
17-
assert.match(headers, /Keep-Alive: timeout=5\r\n/m);
17+
assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m);
1818
assert.match(body, /Hello World!/m);
1919
}
2020
}
Collapse file

‎test/parallel/test-http-keep-alive-pipeline-max-requests.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-keep-alive-pipeline-max-requests.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const bodySent = 'This is my request';
1010
function assertResponse(headers, body, expectClosed) {
1111
if (expectClosed) {
1212
assert.match(headers, /Connection: close\r\n/m);
13-
assert.strictEqual(headers.search(/Keep-Alive: timeout=5\r\n/m), -1);
13+
assert.strictEqual(headers.search(/Keep-Alive: timeout=5, max=3\r\n/m), -1);
1414
assert.match(body, /Hello World!/m);
1515
} else {
1616
assert.match(headers, /Connection: keep-alive\r\n/m);
17-
assert.match(headers, /Keep-Alive: timeout=5\r\n/m);
17+
assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m);
1818
assert.match(body, /Hello World!/m);
1919
}
2020
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.