Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added optional app.head() support

  • Loading branch information...
commit 2876424240c95a3412985839a7d264bbd5634c17 1 parent 74a0177
TJ Holowaychuk tj authored
Showing with 14 additions and 4 deletions.
  1. +12 −3 lib/router/index.js
  2. +2 −1  test/app.head.js
15 lib/router/index.js
View
@@ -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
@@ -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]) {
3  test/app.head.js
View
@@ -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){
Please sign in to comment.
Something went wrong with that request. Please try again.