diff --git a/__tests__/index.js b/__tests__/index.js index 9be130e..33562da 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -245,16 +245,30 @@ describe('Compress', () => { .expect(200, done) }) - it('should not crash if no accept-encoding is sent', (done) => { + it('should not compress if no accept-encoding is sent', (done) => { const app = new Koa() - - app.use(compress()) - app.use(sendBuffer) + app.use(compress({ + threshold: 0 + })) + app.use((ctx) => { + ctx.type = 'text' + ctx.body = buffer + }) server = app.listen() request(server) .get('/') - .expect(200, done) + .unset('accept-encoding') + .end((err, res) => { + if (err) { return done(err) } + + assert(!res.headers['content-encoding']) + assert(!res.headers['transfer-encoding']) + assert.equal(res.headers['content-length'], '1024') + assert.equal(res.headers.vary, 'Accept-Encoding') + + done() + }) }) it('should not crash if a type does not pass the filter', (done) => { diff --git a/lib/index.js b/lib/index.js index 582a912..a1841bb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -61,7 +61,7 @@ module.exports = (options = {}) => { const encodings = new Encodings({ preferredEncodings }) - encodings.parseAcceptEncoding(ctx.request.headers['accept-encoding'] || undefined) + encodings.parseAcceptEncoding(ctx.request.headers['accept-encoding'] || 'identity') const encoding = encodings.getPreferredContentEncoding() // identity === no compression