Skip to content

Commit

Permalink
Added optional app.head() support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 11, 2011
1 parent 74a0177 commit 2876424
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/router/index.js
Expand Up @@ -331,7 +331,7 @@ Router.prototype._optionsFor = function(path){
* @api private
*/

Router.prototype._match = function(req, i){
Router.prototype._match = function(req, i, head){
var method = req.method.toLowerCase()
, url = parse(req.url)
, path = url.pathname
Expand All @@ -340,8 +340,17 @@ Router.prototype._match = function(req, i){
, route
, keys;

// pass HEAD to GET routes
if ('head' == method) method = 'get';
// HEAD support
// TODO: clean this up
if (!head && 'head' == method) {
// attempt lookup
route = this._match(req, i, true);
if (route) return route;

// default to GET as res.render() / res.send()
// etc support HEAD
method = 'get';
}

// routes for this method
if (routes = routes[method]) {
Expand Down
3 changes: 2 additions & 1 deletion test/app.head.js
Expand Up @@ -24,7 +24,8 @@ describe('app.head()', function(){
, called;

app.head('/tobi', function(req, res){
res.end();
called = true;
res.end('');
});

app.get('/tobi', function(req, res){
Expand Down

0 comments on commit 2876424

Please sign in to comment.