Skip to content

Instantly share code, notes, and snippets.

@yssk22r
Created August 25, 2011 05:14
Show Gist options
  • Save yssk22r/1170024 to your computer and use it in GitHub Desktop.
Save yssk22r/1170024 to your computer and use it in GitHub Desktop.
Node http timeout
#!/usr/bin/env node
var http = require('http');
var server = http.createServer(function(req, res){
}).listen(8080, function(){
// a('api.vcap.me');
a('localhost', 8080);
});
function a(host, port){
var req = http.get({
host: host,
port: port || 80,
path: '/'
});
req.on('response', function(res){
console.log('res');
});
req.socket.setTimeout(1000, function(){
req.socket.destroy();
console.log('timeout');
});
req.on('error', function(e){
console.log(e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment