diff --git a/index.js b/index.js index c0638e08..05d66328 100644 --- a/index.js +++ b/index.js @@ -171,6 +171,12 @@ function compression (options) { return } + // response is partial content + if (res.statusCode === 206) { + nocompress('partial content') + return + } + // vary vary(res, 'Accept-Encoding') diff --git a/test/compression.js b/test/compression.js index 8107def0..77de019d 100644 --- a/test/compression.js +++ b/test/compression.js @@ -67,6 +67,25 @@ describe('compression()', function () { .expect(200, 'hello, world', done) }) + it('should skip partial content responses', function (done) { + var server = createServer({ threshold: 0 }, function (req, res) { + res.statusCode = 206 + res.setHeader('Content-Type', 'text/plain') + res.setHeader('Content-Range', 'bytes 0-4/12') + res.setHeader('Content-Length', '5') + res.end('hello') + }) + + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .set('Range', 'bytes=0-4') + .expect(shouldNotHaveHeader('Content-Encoding')) + .expect('Content-Range', 'bytes 0-4/12') + .expect('Content-Length', '5') + .expect(206, 'hello', done) + }) + it('should set Vary', function (done) { var server = createServer({ threshold: 0 }, function (req, res) { res.setHeader('Content-Type', 'text/plain')