2010-12-04 15:20:34 -08:00
|
|
|
var common = require('../common');
|
2010-12-06 01:33:52 +03:00
|
|
|
var assert = require('assert');
|
2010-12-04 15:20:34 -08:00
|
|
|
var http = require('http');
|
2010-05-12 10:01:27 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var server = http.createServer(function(req, res) {
|
2010-06-23 17:40:51 -07:00
|
|
|
console.log('got request. setting 1 second timeout');
|
2010-05-12 10:01:27 -07:00
|
|
|
req.connection.setTimeout(500);
|
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
req.connection.addListener('timeout', function() {
|
2011-01-20 17:07:44 -08:00
|
|
|
req.connection.destroy();
|
2010-12-06 01:33:52 +03:00
|
|
|
common.debug('TIMEOUT');
|
2010-05-12 10:01:27 -07:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
console.log('Server running at http://127.0.0.1:' + common.PORT + '/');
|
2010-05-12 10:01:27 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var errorTimer = setTimeout(function() {
|
2010-05-12 10:01:27 -07:00
|
|
|
throw new Error('Timeout was not sucessful');
|
|
|
|
}, 2000);
|
|
|
|
|
2011-01-20 17:07:44 -08:00
|
|
|
var url = 'http://localhost:' + common.PORT + '/';
|
|
|
|
|
|
|
|
http.cat(url, 'utf8', function(err, content) {
|
|
|
|
clearTimeout(errorTimer);
|
|
|
|
console.log('HTTP REQUEST COMPLETE (this is good)');
|
|
|
|
});
|
2010-05-12 10:01:27 -07:00
|
|
|
});
|