node/test/simple/test-http-head-request.js

34 lines
788 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
var http = require('http');
var util = require('util');
2010-12-05 07:20:34 +08:00
var body = "hello world\n";
2010-12-05 07:20:34 +08:00
var server = http.createServer(function (req, res) {
common.error('req: ' + req.method);
res.writeHead(200, {"Content-Length": body.length});
res.end();
server.close();
});
var gotEnd = false;
server.listen(common.PORT, function () {
var client = http.createClient(common.PORT);
var request = client.request("HEAD", "/");
request.end();
request.addListener('response', function (response) {
common.error('response start');
response.addListener("end", function () {
common.error('response end');
gotEnd = true;
});
});
});
process.addListener('exit', function () {
assert.ok(gotEnd);
});