diff --git a/History.md b/History.md index 46f935c5..5fddc579 100644 --- a/History.md +++ b/History.md @@ -2,6 +2,7 @@ unreleased ========== * Deprecate leading `:` in `name` for `app.param(name, fn)` + * Fix `OPTIONS` responses to include the `HEAD` method properly 4.10.8 / 2015-01-13 =================== diff --git a/lib/router/route.js b/lib/router/route.js index 903d1a5e..6213b821 100644 --- a/lib/router/route.js +++ b/lib/router/route.js @@ -52,10 +52,20 @@ Route.prototype._handles_method = function _handles_method(method) { * @api private */ -Route.prototype._options = function(){ - return Object.keys(this.methods).map(function(method) { - return method.toUpperCase(); - }); +Route.prototype._options = function _options() { + var methods = Object.keys(this.methods); + + // append automatic head + if (this.methods.get && !this.methods.head) { + methods.push('head'); + } + + for (var i = 0; i < methods.length; i++) { + // make upper case + methods[i] = methods[i].toUpperCase(); + } + + return methods; }; /** diff --git a/test/app.options.js b/test/app.options.js index 30890c05..20234723 100644 --- a/test/app.options.js +++ b/test/app.options.js @@ -12,8 +12,8 @@ describe('OPTIONS', function(){ request(app) .options('/users') - .expect('GET,PUT') - .expect('Allow', 'GET,PUT', done); + .expect('Allow', 'GET,HEAD,PUT') + .expect(200, 'GET,HEAD,PUT', done); }) it('should only include each method once', function(done){ @@ -26,8 +26,8 @@ describe('OPTIONS', function(){ request(app) .options('/users') - .expect('GET,PUT') - .expect('Allow', 'GET,PUT', done); + .expect('Allow', 'GET,HEAD,PUT') + .expect(200, 'GET,HEAD,PUT', done); }) it('should not be affected by app.all', function(done){ @@ -44,8 +44,8 @@ describe('OPTIONS', function(){ request(app) .options('/users') .expect('x-hit', '1') - .expect('allow', 'GET,PUT') - .expect(200, 'GET,PUT', done); + .expect('Allow', 'GET,HEAD,PUT') + .expect(200, 'GET,HEAD,PUT', done); }) it('should not respond if the path is not defined', function(done){ @@ -68,8 +68,8 @@ describe('OPTIONS', function(){ request(app) .options('/other') - .expect('GET') - .expect('Allow', 'GET', done); + .expect('Allow', 'GET,HEAD') + .expect(200, 'GET,HEAD', done); }) describe('when error occurs in respone handler', function () {