Skip to content

Commit 851264c

Browse 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

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎lib/_http_outgoing.js‎

Lines 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
consttimeoutSeconds=MathFloor(this._keepAliveTimeout/1000);
466-
header+=`Keep-Alive: timeout=${timeoutSeconds}\r\n`;
466+
letmax='';
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‎

Lines 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
constres=newserver[kServerResponse](req);
961961
res._keepAliveTimeout=server.keepAliveTimeout;
962+
res._maxRequestsPerSocket=server.maxRequestsPerSocket;
962963
res._onPendingData=updateOutgoingData.bind(undefined,
963964
socket,state);
964965

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

Lines 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,/HelloWorld!/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,/HelloWorld!/m);
1919
}
2020
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const bodySent = 'This is my request';
1010
functionassertResponse(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,/HelloWorld!/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,/HelloWorld!/m);
1919
}
2020
}

0 commit comments

Comments
 (0)