diff --git a/__tests__/index.js b/__tests__/index.js index 33562da..9be130e 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -245,30 +245,16 @@ describe('Compress', () => { .expect(200, done) }) - it('should not compress if no accept-encoding is sent', (done) => { + it('should not crash if no accept-encoding is sent', (done) => { const app = new Koa() - app.use(compress({ - threshold: 0 - })) - app.use((ctx) => { - ctx.type = 'text' - ctx.body = buffer - }) + + app.use(compress()) + app.use(sendBuffer) server = app.listen() request(server) .get('/') - .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() - }) + .expect(200, 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 a1841bb..582a912 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'] || 'identity') + encodings.parseAcceptEncoding(ctx.request.headers['accept-encoding'] || undefined) const encoding = encodings.getPreferredContentEncoding() // identity === no compression