Skip to content

Commit

Permalink
Revert "Use identity as default value for Accept-Encoding if it is bl…
Browse files Browse the repository at this point in the history
…ank or not provided (#110)"

This reverts commit 3d4c0ac.
  • Loading branch information
niftylettuce committed Jul 6, 2020
1 parent 3d4c0ac commit 0139443
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 5 additions & 19 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0139443

Please sign in to comment.