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-04-12 03:21:33 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
|
|
|
var util = require('util');
|
2010-04-12 03:21:33 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var body = 'hello world';
|
2010-04-12 03:21:33 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
res.writeHeader(200,
|
|
|
|
{'Content-Length': body.length.toString(),
|
|
|
|
'Content-Type': 'text/plain'
|
|
|
|
});
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log('method: ' + req.method);
|
2010-04-12 03:21:33 +08:00
|
|
|
if (req.method != 'HEAD') res.write(body);
|
|
|
|
res.end();
|
|
|
|
});
|
2010-07-16 02:47:25 +08:00
|
|
|
server.listen(common.PORT);
|
2010-04-12 03:21:33 +08:00
|
|
|
|
|
|
|
var gotEnd = false;
|
|
|
|
|
2011-10-15 07:08:36 +08:00
|
|
|
server.on('listening', function() {
|
2011-08-14 14:02:14 +08:00
|
|
|
var request = http.request({
|
2011-10-05 06:08:18 +08:00
|
|
|
port: common.PORT,
|
2011-08-14 14:02:14 +08:00
|
|
|
method: 'HEAD',
|
2011-10-05 06:08:18 +08:00
|
|
|
path: '/'
|
2011-08-14 14:02:14 +08:00
|
|
|
}, function(response) {
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log('got response');
|
2011-10-15 07:08:36 +08:00
|
|
|
response.on('data', function() {
|
2010-04-12 03:21:33 +08:00
|
|
|
process.exit(2);
|
|
|
|
});
|
2011-10-15 07:08:36 +08:00
|
|
|
response.on('end', function() {
|
2010-04-12 03:21:33 +08:00
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
request.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
//give a bit of time for the server to respond before we check it
|
|
|
|
setTimeout(function() {
|
|
|
|
process.exit(1);
|
|
|
|
}, 2000);
|