Skip to content

Commit f351090

Browse files
committed
Improve detection of zero-length body without Content-Length
1 parent 2403c20 commit f351090

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Improve detection of zero-length body without `Content-Length`
45
* deps: accepts@~1.2.9
56
- deps: mime-types@~2.1.1
67
- perf: avoid argument reassignment & argument slice

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function addListeners(stream, on, listeners) {
217217

218218
function chunkLength(chunk, encoding) {
219219
if (!chunk) {
220-
return
220+
return 0
221221
}
222222

223223
return !Buffer.isBuffer(chunk)

test/compression.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ describe('compression()', function(){
395395
.expect(200, '....', done)
396396
})
397397

398+
it('should consider res.end() as 0 length', function(done){
399+
var server = createServer({ threshold: 1 }, function (req, res) {
400+
res.setHeader('Content-Type', 'text/plain')
401+
res.end()
402+
})
403+
404+
request(server)
405+
.get('/')
406+
.set('Accept-Encoding', 'gzip')
407+
.expect(shouldNotHaveHeader('Content-Encoding'))
408+
.expect(200, '', done)
409+
})
410+
398411
it('should work with res.end(null)', function (done) {
399412
var server = createServer({ threshold: 1000 }, function (req, res) {
400413
res.setHeader('Content-Type', 'text/plain')
@@ -404,6 +417,7 @@ describe('compression()', function(){
404417
request(server)
405418
.get('/')
406419
.set('Accept-Encoding', 'gzip')
420+
.expect(shouldNotHaveHeader('Content-Encoding'))
407421
.expect(200, '', done)
408422
})
409423
})

0 commit comments

Comments
 (0)