Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
var http = require('http'),
EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var server = http.createServer(function (req, res, proxy) {
emitter.on('done', function (e) {
if(e) {
res.writeHead(502);
res.end();
}
else {
res.writeHead(200);
res.end();
}
})
var options = {
host: 'localhost',
port: 8000,
path: '/someslowresource',
method: 'GET'
};
var happy = false;
var clientReq = http.request(options, function (clientRes) {
happy = true;
emitter.emit('done');
});
clientReq.setTimeout(1200, function () {
if(happy) {
console.log('in timeout');
}
emitter.emit('done', {
message: 'timeout'
});
});
clientReq.on('error', function () {
console.log('in error');
clientReq.connection.destroy();
emitter.emit({
message: 'error'
});
})
clientReq.end();
});
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.