diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index dcdea29968590a..7b1961ad978580 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -463,7 +463,11 @@ function _storeHeader(firstLine, headers) { header += 'Connection: keep-alive\r\n'; if (this._keepAliveTimeout && this._defaultKeepAlive) { const timeoutSeconds = MathFloor(this._keepAliveTimeout / 1000); - header += `Keep-Alive: timeout=${timeoutSeconds}\r\n`; + let max = ''; + if (~~this._maxRequestsPerSocket > 0) { + max = `, max=${this._maxRequestsPerSocket}`; + } + header += `Keep-Alive: timeout=${timeoutSeconds}${max}\r\n`; } } else { this._last = true; diff --git a/lib/_http_server.js b/lib/_http_server.js index 5f54295c8a1563..da98e949f2d1f7 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -955,6 +955,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { const res = new server[kServerResponse](req); res._keepAliveTimeout = server.keepAliveTimeout; + res._maxRequestsPerSocket = server.maxRequestsPerSocket; res._onPendingData = updateOutgoingData.bind(undefined, socket, state); diff --git a/test/parallel/test-http-keep-alive-max-requests.js b/test/parallel/test-http-keep-alive-max-requests.js index 9412bceffb63aa..160891e500e46a 100644 --- a/test/parallel/test-http-keep-alive-max-requests.js +++ b/test/parallel/test-http-keep-alive-max-requests.js @@ -14,7 +14,7 @@ function assertResponse(headers, body, expectClosed) { assert.match(body, /Hello World!/m); } else { assert.match(headers, /Connection: keep-alive\r\n/m); - assert.match(headers, /Keep-Alive: timeout=5\r\n/m); + assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m); assert.match(body, /Hello World!/m); } } diff --git a/test/parallel/test-http-keep-alive-pipeline-max-requests.js b/test/parallel/test-http-keep-alive-pipeline-max-requests.js index 9c5d46a57ce197..5549440d3dd5ae 100644 --- a/test/parallel/test-http-keep-alive-pipeline-max-requests.js +++ b/test/parallel/test-http-keep-alive-pipeline-max-requests.js @@ -10,11 +10,11 @@ const bodySent = 'This is my request'; function assertResponse(headers, body, expectClosed) { if (expectClosed) { assert.match(headers, /Connection: close\r\n/m); - assert.strictEqual(headers.search(/Keep-Alive: timeout=5\r\n/m), -1); + assert.strictEqual(headers.search(/Keep-Alive: timeout=5, max=3\r\n/m), -1); assert.match(body, /Hello World!/m); } else { assert.match(headers, /Connection: keep-alive\r\n/m); - assert.match(headers, /Keep-Alive: timeout=5\r\n/m); + assert.match(headers, /Keep-Alive: timeout=5, max=3\r\n/m); assert.match(body, /Hello World!/m); } }