Permalink
Browse files

Merge pull request #1451 from aweeks/fix-304-must-not-contain-body

Explicitly remove Transfer-Encoding header from 204 and 304 responses
  • Loading branch information...
2 parents ce7d7bf + a1e42ac commit 3c4fd57e5162a303ab91f24aa55058a233f377b6 @tj tj 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 3c4fd57

Please sign in to comment.