-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: provide keep-alive timeout response header
In http 1.1 persistent connection protocol there is a timing race where the client sends the request and then the server kills the connection (due to inactivity) before receiving the client's request. By providing a keep-alive header it is possible to provide the client a hint of when idle timeout would occur and avoid the race. Fixes: #34560 PR-URL: #34561 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
- Loading branch information
1 parent
c1abc8d
commit 36fd3da
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
const assert = require('assert'); | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
const body = 'hello world\n'; | ||
|
||
res.writeHead(200, { 'Content-Length': body.length }); | ||
res.write(body); | ||
res.end(); | ||
})); | ||
server.keepAliveTimeout = 12000; | ||
|
||
const agent = new http.Agent({ maxSockets: 1, keepAlive: true }); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
http.get({ | ||
path: '/', port: this.address().port, agent: agent | ||
}, common.mustCall((response) => { | ||
response.resume(); | ||
assert.strictEqual( | ||
response.headers['keep-alive'], 'timeout=12'); | ||
server.close(); | ||
agent.destroy(); | ||
})); | ||
})); |