Skip to content

Commit 628c524

Browse files
tkesgardougwilson
authored andcommitted
Support proper 205 responses using res.send
closes #4592 closes #4596
1 parent e693771 commit 628c524

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Support proper 205 responses using `res.send`
5+
16
4.17.3 / 2022-02-16
27
===================
38

lib/response.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ res.send = function send(body) {
213213
chunk = '';
214214
}
215215

216+
// alter headers for 205
217+
if (this.statusCode === 205) {
218+
this.set('Content-Length', '0')
219+
this.removeHeader('Transfer-Encoding')
220+
chunk = ''
221+
}
222+
216223
if (req.method === 'HEAD') {
217224
// skip body for HEAD
218225
this.end();

test/res.send.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ describe('res', function(){
283283
})
284284
})
285285

286+
describe('when .statusCode is 205', function () {
287+
it('should strip Transfer-Encoding field and body, set Content-Length', function (done) {
288+
var app = express()
289+
290+
app.use(function (req, res) {
291+
res.status(205).set('Transfer-Encoding', 'chunked').send('foo')
292+
})
293+
294+
request(app)
295+
.get('/')
296+
.expect(utils.shouldNotHaveHeader('Transfer-Encoding'))
297+
.expect('Content-Length', '0')
298+
.expect(205, '', done)
299+
})
300+
})
301+
286302
describe('when .statusCode is 304', function(){
287303
it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){
288304
var app = express();

0 commit comments

Comments
 (0)