Skip to content

Commit fa6183f

Browse files
theanarkhjuanarbol
authored andcommittedOct 11, 2022
http: add max for http keepalive
PR-URL: #44217 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent ff34d48 commit fa6183f

4 files changed

+9
-4
lines changed
 

‎lib/_http_outgoing.js

+5-1
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;

‎lib/_http_server.js

+1
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
922922

923923
const res = new server[kServerResponse](req);
924924
res._keepAliveTimeout = server.keepAliveTimeout;
925+
res._maxRequestsPerSocket = server.maxRequestsPerSocket;
925926
res._onPendingData = updateOutgoingData.bind(undefined,
926927
socket, state);
927928

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

+1-1
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
}

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

+2-2
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)
Please sign in to comment.