parser.incoming.upgrade = info.upgrade;
+ var isHeadResponse = false;
+
if (!info.upgrade) {
// For upgraded connections, we'll emit this after parser.execute
// so that we can capture the first part of the new protocol
- parser.onIncoming(parser.incoming, info.shouldKeepAlive);
+ isHeadResponse = parser.onIncoming(parser.incoming, info.shouldKeepAlive);
}
- return false; // Is response to HEAD request?
+ return isHeadResponse;
};
parser.onBody = function (b, start, len) {
function ClientRequest (socket, method, url, headers) {
OutgoingMessage.call(this, socket);
+ this.method = method;
this.shouldKeepAlive = false;
if (method === "GET" || method === "HEAD") {
this.useChunkedEncodingByDefault = false;
responses.push(res);
self.emit('request', req, res);
+ return false; // Not a HEAD response. (Not even a response!)
};
}
if (!parser) parser = parsers.alloc();
parser.reinitialize('response');
parser.socket = self;
+ parser.reqs = []; // list of request methods
parser.onIncoming = function (res) {
debug("incoming response!");
+ var isHeadResponse = currentRequest.method == "HEAD";
+ debug('isHeadResponse ' + isHeadResponse);
+
res.addListener('end', function ( ) {
debug("request complete disconnecting. readyState = " + self.readyState);
self.end();
});
currentRequest.emit("response", res);
+
+ return isHeadResponse;
};
};
--- /dev/null
+require('../common');
+
+assert = require("assert");
+http = require("http");
+sys = require("sys");
+
+
+body = "hello world\n";
+
+server = http.createServer(function (req, res) {
+ error('req: ' + req.method);
+ res.writeHead(200, {"Content-Length": body.length});
+ res.end();
+ server.close();
+});
+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) {
+ error('response start');
+ response.addListener("end", function () {
+ error('response end');
+ gotEnd = true;
+ });
+ });
+ request.end();
+});
+
+process.addListener('exit', function () {
+ assert.ok(gotEnd);
+});