Skip to content

Commit

Permalink
Test that a missing Accept-Encoding header should not result in compr…
Browse files Browse the repository at this point in the history
…ession
  • Loading branch information
dobesv committed May 14, 2020
1 parent cce99c4 commit a68d849
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,29 @@ 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((ctx, next) => {
if('accept-encoding' in ctx.headers)
throw new Error(`Unexpected Accept-Encoding: ${ctx.headers['accept-encoding']}`)
return next();
})
app.use(compress({
threshold: 0
}))
app.use((ctx) => {
ctx.type = 'text'
ctx.body = 'not compressed'
})
server = app.listen()

request(server)
.get('/')
.expect(200, done)
.unset('accept-encoding')
.expect(res => !('vary' in res.headers))
.expect(res => !('content-encoding' in res.headers))
.expect('not compressed', done)
})

it('should not crash if a type does not pass the filter', (done) => {
Expand Down

0 comments on commit a68d849

Please sign in to comment.