fix overwriting of content-type w/ HEAD requests
This commit is contained in:
parent
a18ee8143d
commit
52cb57cc7e
3 changed files with 21 additions and 1 deletions
|
@ -4,6 +4,7 @@ HEAD
|
||||||
|
|
||||||
* fix: inspection of `app` and `app.toJSON()`
|
* fix: inspection of `app` and `app.toJSON()`
|
||||||
* fix: let `this.throw`n errors provide their own status
|
* fix: let `this.throw`n errors provide their own status
|
||||||
|
* fix: overwriting of `content-type` w/ `HEAD` requests
|
||||||
* refactor: use statuses
|
* refactor: use statuses
|
||||||
* refactor: use escape-html
|
* refactor: use escape-html
|
||||||
|
|
||||||
|
|
|
@ -179,8 +179,11 @@ function *respond(next){
|
||||||
// ignore body
|
// ignore body
|
||||||
if (status.empty[code]) return res.end();
|
if (status.empty[code]) return res.end();
|
||||||
|
|
||||||
// status body
|
|
||||||
if (null == body) {
|
if (null == body) {
|
||||||
|
// empty body
|
||||||
|
if (head) return res.end();
|
||||||
|
|
||||||
|
// status body
|
||||||
this.type = 'text';
|
this.type = 'text';
|
||||||
body = status[code];
|
body = status[code];
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,22 @@ describe('app.respond', function(){
|
||||||
.head('/')
|
.head('/')
|
||||||
.expect(200, done);
|
.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(){
|
describe('when no middleware are present', function(){
|
||||||
|
|
Loading…
Reference in a new issue