add striping of Content-* fields when 204 / 304. Closes #21
This commit is contained in:
parent
b9d4d2031d
commit
1457a3df0f
2 changed files with 30 additions and 0 deletions
|
@ -71,6 +71,12 @@ module.exports = {
|
|||
val = n;
|
||||
}
|
||||
|
||||
if (204 == val || 304 == val) {
|
||||
this.res.removeHeader('Content-Type');
|
||||
this.res.removeHeader('Content-Length');
|
||||
this.res.removeHeader('Transfer-Encoding');
|
||||
}
|
||||
|
||||
this.res.statusCode = val;
|
||||
},
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
var _context = require('../lib/context');
|
||||
var request = require('supertest');
|
||||
var assert = require('assert');
|
||||
var koa = require('..');
|
||||
var fs = require('fs');
|
||||
|
@ -172,6 +173,29 @@ describe('ctx.status=', function(){
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when 204', function(){
|
||||
it('should strip content related header fields', function(done){
|
||||
var app = koa();
|
||||
|
||||
app.use(function(next){
|
||||
return function *(){
|
||||
this.set('Content-Type', 'application/json');
|
||||
this.set('Content-Length', '15');
|
||||
this.set('Transfer-Encoding', 'chunked');
|
||||
this.status = 204;
|
||||
assert(null == this.responseHeader['content-type']);
|
||||
assert(null == this.responseHeader['content-length']);
|
||||
assert(null == this.responseHeader['transfer-encoding']);
|
||||
}
|
||||
});
|
||||
|
||||
request(app.listen())
|
||||
.get('/')
|
||||
.expect(204)
|
||||
.end(done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ctx.stale', function(){
|
||||
|
|
Loading…
Reference in a new issue