Permalink
Browse files

Explicitly remove Transfer-Encoding header from 204 and 304 responses

Per RFC 2616 §10.3.6 & §10.2.5 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) "The [204/304] response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields."
  • Loading branch information...
1 parent ce7d7bf commit a1e42ac33fc5ab7c29aeed79879322ffb0468ed7 Alex Weeks committed Dec 19, 2012
Showing with 7 additions and 4 deletions.
  1. +1 −0 lib/response.js
  2. +6 −4 test/res.send.js
View
@@ -141,6 +141,7 @@ res.send = function(body){
if (204 == this.statusCode || 304 == this.statusCode) {
this.removeHeader('Content-Type');
this.removeHeader('Content-Length');
+ this.removeHeader('Transfer-Encoding');
body = '';
}
View
@@ -206,37 +206,39 @@ describe('res', function(){
})
describe('when .statusCode is 204', function(){
- it('should strip Content-* fields & body', function(done){
+ it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){
var app = express();
app.use(function(req, res){
- res.status(204).send('foo');
+ res.status(204).set('Transfer-Encoding', 'chunked').send('foo');
});
request(app)
.get('/')
.end(function(err, res){
res.headers.should.not.have.property('content-type');
res.headers.should.not.have.property('content-length');
+ res.headers.should.not.have.property('transfer-encoding');
res.text.should.equal('');
done();
})
})
})
describe('when .statusCode is 304', function(){
- it('should strip Content-* fields & body', function(done){
+ it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){
var app = express();
app.use(function(req, res){
- res.status(304).send('foo');
+ res.status(304).set('Transfer-Encoding', 'chunked').send('foo');
});
request(app)
.get('/')
.end(function(err, res){
res.headers.should.not.have.property('content-type');
res.headers.should.not.have.property('content-length');
+ res.headers.should.not.have.property('transfer-encoding');
res.text.should.equal('');
done();
})

0 comments on commit a1e42ac

Please sign in to comment.