Skip to content

Commit bec3ccd

Browse files
bug fix - undefined value of compressible now does not compress (#102)
* undefined value of compressible now does not compress * test added for skipping compression for mime types for which compressible value is false
1 parent 5521ed6 commit bec3ccd

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function shouldCompress (type, compressibleTypes) {
258258
if (compressibleTypes.test(type)) return true
259259
var data = mimedb[type.split(';', 1)[0].trim().toLowerCase()]
260260
if (data === undefined) return false
261-
return data.compressible
261+
return data.compressible === true
262262
}
263263

264264
function isCompressed (data) {

test/test-global.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,3 +1611,26 @@ test('Should error if no entries in `encodings` are supported', t => {
16111611
t.ok(err instanceof Error)
16121612
})
16131613
})
1614+
1615+
test('Should not compress mime types with undefined compressible values', t => {
1616+
t.plan(4)
1617+
const fastify = Fastify()
1618+
fastify.register(compressPlugin, { brotli, threshold: 0 })
1619+
1620+
fastify.get('/', (req, reply) => {
1621+
reply.type('image/webp').send('hello')
1622+
})
1623+
1624+
fastify.inject({
1625+
url: '/',
1626+
method: 'GET',
1627+
headers: {
1628+
'accept-encoding': 'gzip, deflate, br'
1629+
}
1630+
}, (err, res) => {
1631+
t.error(err)
1632+
t.strictEqual(res.statusCode, 200)
1633+
t.notOk(res.headers['content-encoding'])
1634+
t.strictEqual(res.payload, 'hello')
1635+
})
1636+
})

0 commit comments

Comments
 (0)