Skip to content

Commit b498c57

Browse files
authored
fix: prevents fastify-compress from trying to work with something it cannot
Sending something other than buffers of strings in the `payload` happens, but this would break the later `Buffer.byteLength(payload)` Signed-off-by: Bart Riepe <bart@serial-experiments.com>
1 parent 331457b commit b498c57

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ function buildRouteCompress (_fastify, params, routeOptions, decorateOnly) {
272272
return next(null, payload)
273273
}
274274

275+
// Don't compress uncompressable things
276+
if (!Buffer.isBuffer(payload) && typeof payload !== "string") {
277+
return next(null, payload);
278+
}
279+
275280
if (typeof payload.pipe !== 'function') {
276281
if (Buffer.byteLength(payload) < params.threshold) {
277282
return next()

0 commit comments

Comments
 (0)