2011-03-10 16:54:52 +08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
2010-12-06 06:33:52 +08:00
|
|
|
var assert = require('assert');
|
2010-12-05 07:20:34 +08:00
|
|
|
var http = require('http');
|
2010-05-13 01:01:27 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var server = http.createServer(function(req, res) {
|
2011-07-06 06:42:32 +08:00
|
|
|
console.log('got request. setting 1 second timeout');
|
|
|
|
req.connection.setTimeout(500);
|
2010-05-13 01:01:27 +08:00
|
|
|
|
2011-10-15 07:08:36 +08:00
|
|
|
req.connection.on('timeout', function() {
|
2011-07-06 06:42:32 +08:00
|
|
|
req.connection.destroy();
|
2010-12-06 06:33:52 +08:00
|
|
|
common.debug('TIMEOUT');
|
2010-05-13 01:01:27 +08:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
console.log('Server running at http://127.0.0.1:' + common.PORT + '/');
|
2010-05-13 01:01:27 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var errorTimer = setTimeout(function() {
|
2010-05-13 01:01:27 +08:00
|
|
|
throw new Error('Timeout was not sucessful');
|
|
|
|
}, 2000);
|
|
|
|
|
2011-10-05 06:08:18 +08:00
|
|
|
var x = http.get({port: common.PORT, path: '/'});
|
|
|
|
x.on('error', function() {
|
2011-01-21 09:07:44 +08:00
|
|
|
clearTimeout(errorTimer);
|
|
|
|
console.log('HTTP REQUEST COMPLETE (this is good)');
|
2011-10-05 06:08:18 +08:00
|
|
|
});
|
2011-08-04 06:06:16 +08:00
|
|
|
x.end();
|
|
|
|
|
2010-05-13 01:01:27 +08:00
|
|
|
});
|