Skip to content
Myr

Explicitly remove Transfer-Encoding header from 204 and 304 responses

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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."

authored by Alex Weeks · committed by Alex Weeks · parent ce7d7bf · Browse files · 2 files+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−4 removed

  • tests:+6 added−4 removed
  • other:+1 added−0 removed

2 files+7 added−4 removed

modified:lib/response.js+1 added
139 unmodified lines
140 // strip irrelevant headers141 if (204 == this.statusCode || 304 == this.statusCode) {142 this.removeHeader('Content-Type');143 this.removeHeader('Content-Length');144 this.removeHeader('Transfer-Encoding');145 body = '';146 }147148 // respond
570 unmodified lines
modified:test/res.send.js+6 added-4 removed
204 unmodified lines
205 })206 })207208 describe('when .statusCode is 204', function(){209 it('should strip Content-* fields & body', function(done){209 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){210 var app = express();211212 app.use(function(req, res){213 res.status(204).send('foo');213 res.status(204).set('Transfer-Encoding', 'chunked').send('foo');214 });215216 request(app)217 .get('/')218 .end(function(err, res){219 res.headers.should.not.have.property('content-type');220 res.headers.should.not.have.property('content-length');221 res.headers.should.not.have.property('transfer-encoding');222 res.text.should.equal('');223 done();224 })225 })226 })227 228 describe('when .statusCode is 304', function(){228 it('should strip Content-* fields & body', function(done){229 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){230 var app = express();231232 app.use(function(req, res){232 res.status(304).send('foo');233 res.status(304).set('Transfer-Encoding', 'chunked').send('foo');234 });235236 request(app)237 .get('/')238 .end(function(err, res){239 res.headers.should.not.have.property('content-type');240 res.headers.should.not.have.property('content-length');241 res.headers.should.not.have.property('transfer-encoding');242 res.text.should.equal('');243 done();244 })245 })
58 unmodified lines