fastify-compress
Advanced tools
Comparing version 3.4.0 to 3.4.1
12
index.js
@@ -22,2 +22,4 @@ 'use strict' | ||
const compressAdded = Symbol('fastify-compress.added') | ||
function compressPlugin (fastify, opts, next) { | ||
@@ -183,2 +185,12 @@ const globalCompressParams = processCompressParams(opts) | ||
function buildRouteCompress (fastify, params, routeOptions, decorateOnly) { | ||
// This methods works by altering the routeOptions, it has side effects. | ||
// There is the possibility that the same options are set for more than | ||
// one route, so we just need to make sure that the hook is addded only | ||
// once. | ||
if (routeOptions[compressAdded]) { | ||
return | ||
} | ||
routeOptions[compressAdded] = true | ||
// In order to provide a compress method with the same parameter set as the route itself has | ||
@@ -185,0 +197,0 @@ // we do the decorate the reply at the start of the request |
{ | ||
"name": "fastify-compress", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "Fastify compression utils", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"tap": "^14.10.8", | ||
"tsd": "^0.13.1", | ||
"tsd": "^0.14.0", | ||
"typescript": "^4.0.2" | ||
@@ -34,0 +34,0 @@ }, |
@@ -258,1 +258,28 @@ 'use strict' | ||
}) | ||
test('avoid double onSend', t => { | ||
t.plan(2) | ||
const server = Fastify() | ||
server.register(compressPlugin, { | ||
threshold: 0 | ||
}) | ||
server.register(async function (server) { | ||
server.get('/', async (req, _) => { | ||
return { hi: true } | ||
}) | ||
}, { prefix: '/test' }) | ||
server.inject({ | ||
url: '/test', | ||
method: 'GET', | ||
headers: { | ||
'accept-encoding': 'br' | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.deepEqual(JSON.parse(zlib.brotliDecompressSync(res.rawPayload)), { hi: true }) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102068
2909