From 52cb57cc7e7f52a2b500f53692a7c979c98a3bfb Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Sun, 23 Mar 2014 04:01:14 -0700 Subject: [PATCH] fix overwriting of content-type w/ HEAD requests --- History.md | 1 + lib/application.js | 5 ++++- test/application.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 14a3cfc..3f4c1f8 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ HEAD * fix: inspection of `app` and `app.toJSON()` * fix: let `this.throw`n errors provide their own status + * fix: overwriting of `content-type` w/ `HEAD` requests * refactor: use statuses * refactor: use escape-html diff --git a/lib/application.js b/lib/application.js index 1b135ba..80ce7f4 100644 --- a/lib/application.js +++ b/lib/application.js @@ -179,8 +179,11 @@ function *respond(next){ // ignore body if (status.empty[code]) return res.end(); - // status body if (null == body) { + // empty body + if (head) return res.end(); + + // status body this.type = 'text'; body = status[code]; } diff --git a/test/application.js b/test/application.js index 324ea2b..4e0a297 100644 --- a/test/application.js +++ b/test/application.js @@ -189,6 +189,22 @@ describe('app.respond', function(){ .head('/') .expect(200, done); }) + + it('should not overwrite the content-type', function(done){ + var app = koa(); + + app.use(function *(){ + this.status = 200; + this.type = 'application/javascript'; + }) + + var server = app.listen(); + + request(server) + .head('/') + .expect('content-type', 'application/javascript') + .expect(200, done); + }) }) describe('when no middleware are present', function(){