From 93913dbdb8f621bef46c61d1f8a824a19a57dfa5 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 11 Apr 2010 12:21:33 -0700 Subject: [PATCH] Add failing test for HEAD requests Needs to be fixed for 0.2. --- test/simple/test-http-head-request.js | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/simple/test-http-head-request.js diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js new file mode 100644 index 00000000000..671e3ae83bf --- /dev/null +++ b/test/simple/test-http-head-request.js @@ -0,0 +1,39 @@ +require('../common'); + +var assert = require("assert"); +var http = require("http"); +var sys = require("sys"); + +var body = "hello world"; + +server = http.createServer(function (req, res) { + res.writeHeader(200 , { 'Content-Length': body.length.toString() + , 'Content-Type': 'text/plain' + }); + sys.puts('method: ' + req.method); + if (req.method != 'HEAD') res.write(body); + res.end(); +}); +server.listen(PORT); + +var gotEnd = false; + +server.addListener('listening', function() { + var client = http.createClient(PORT); + var request = client.request("HEAD", "/"); + request.addListener('response', function (response) { + sys.puts('got response'); + response.addListener("data", function () { + process.exit(2); + }); + response.addListener("end", function () { + 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);