add striping of Content-* fields when 204 / 304. Closes #21

This commit is contained in:
TJ Holowaychuk 2013-08-20 21:24:18 -07:00
parent b9d4d2031d
commit 1457a3df0f
2 changed files with 30 additions and 0 deletions

View file

@ -71,6 +71,12 @@ module.exports = {
val = n; 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; this.res.statusCode = val;
}, },

View file

@ -1,5 +1,6 @@
var _context = require('../lib/context'); var _context = require('../lib/context');
var request = require('supertest');
var assert = require('assert'); var assert = require('assert');
var koa = require('..'); var koa = require('..');
var fs = require('fs'); 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(){ describe('ctx.stale', function(){