-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: socket connection timeout for http request
This allows passing the socket connection timeout to http#request such that it will be set before the socket is connecting PR-URL: #8101 Fixes: #7580 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
- Loading branch information
Showing
6 changed files
with
58 additions
and
18 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
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,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
var options = { | ||
method: 'GET', | ||
port: undefined, | ||
host: '127.0.0.1', | ||
path: '/', | ||
timeout: 1 | ||
}; | ||
|
||
var server = http.createServer(); | ||
|
||
server.listen(0, options.host, function() { | ||
options.port = this.address().port; | ||
var req = http.request(options); | ||
req.on('error', function() { | ||
// this space is intentionally left blank | ||
}); | ||
req.on('close', common.mustCall(() => server.close())); | ||
|
||
var timeout_events = 0; | ||
req.on('timeout', common.mustCall(() => timeout_events += 1)); | ||
setTimeout(function() { | ||
req.destroy(); | ||
assert.strictEqual(timeout_events, 1); | ||
}, common.platformTimeout(100)); | ||
setTimeout(function() { | ||
req.end(); | ||
}, common.platformTimeout(10)); | ||
}); |