Permalink
Browse files

Add support for HEAD http requests and do not let crash applications

  • Loading branch information...
1 parent fe4824e commit 7f3f850206c3bff40321b3f9701202e7aae1cc5f @djui djui committed with Aug 17, 2010
Showing with 16 additions and 4 deletions.
  1. +16 −4 lib/node-router.js
View
@@ -95,6 +95,9 @@ exports.getServer = function getServer(logger) {
function del(pattern, handler) {
return addRoute("DELETE", pattern, handler);
}
+ function head(pattern, handler) {
+ return addRoute("HEAD", pattern, handler);
+ }
// This is a meta pattern that expands to a common RESTful mapping
function resource(name, controller, format) {
@@ -200,7 +203,13 @@ exports.getServer = function getServer(logger) {
res.notFound = function (message) {
notFound(req, res, message);
};
-
+
+ res.onlyHead = function (code, extra_headers) {
+ res.writeHead(code, (extra_headers || []).concat(
+ [["Content-Type", content_type]]));
+ res.end();
+ }
+
function doRoute() {
uri = url_parse(req.url);
path = uri.pathname;
@@ -245,8 +254,11 @@ exports.getServer = function getServer(logger) {
}
}
}
-
- notFound(req, res);
+
+ if (req.method === "HEAD")
+ res.onlyHead(200);
+ else
+ notFound(req, res);
}
doRoute();
@@ -262,7 +274,7 @@ exports.getServer = function getServer(logger) {
logger("node-router server instance at http://" + host + ":" + port + "/");
} else {
logger("node-router server instance at unix:" + port);
- }
+ }
}
function end() {

0 comments on commit 7f3f850

Please sign in to comment.