Permalink
Browse files

Fix the HEAD http fix

  • Loading branch information...
1 parent 290db66 commit 64834cf3092dc972438993f928c8413df846f289 @djui djui committed with jdub Aug 17, 2010
Showing with 9 additions and 8 deletions.
  1. +9 −8 lib/node-router.js
View
@@ -36,7 +36,8 @@ function notFound(req, res, message) {
"Content-Type": "text/plain",
"Content-Length": message.length
});
- res.write(message);
+ if (req.method !== "HEAD")
+ res.write(message);
res.end();
}
@@ -184,7 +185,8 @@ exports.getServer = function getServer(logger) {
[ ["Content-Type", content_type],
["Content-Length", Buffer.byteLength(body, 'utf8')]
]));
- res.write(body, 'utf8');
+ if (req.method !== "HEAD")
+ res.write(body, 'utf8');
res.end();
}
@@ -255,10 +257,7 @@ exports.getServer = function getServer(logger) {
}
}
- if (req.method === "HEAD")
- res.onlyHead(200);
- else
- notFound(req, res);
+ notFound(req, res);
}
doRoute();
@@ -330,7 +329,8 @@ exports.staticHandler = function (filename) {
return function (req, res) {
loadResponseData(req, res, function () {
res.writeHead(200, headers);
- res.write(body, encoding);
+ if (req.method !== "HEAD")
+ res.write(body, encoding);
res.end();
});
};
@@ -363,7 +363,8 @@ exports.staticDirHandler = function(root, prefix) {
if (filename == root) filename = path.join(root, 'index.html');
loadResponseData(req, res, filename, function(headers, body, encoding) {
res.writeHead(200, headers);
- res.write(body, encoding);
+ if (req.method !== "HEAD")
+ res.write(body, encoding);
res.end();
});
};

0 comments on commit 64834cf

Please sign in to comment.