fix overwriting of content-type w/ HEAD requests

This commit is contained in:
Jonathan Ong 2014-03-23 04:01:14 -07:00
parent a18ee8143d
commit 52cb57cc7e
3 changed files with 21 additions and 1 deletions

View file

@ -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

View file

@ -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];
}

View file

@ -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(){