From 48c4f2eb4449e4807914c4c1a3b765dafd12ccba Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Mon, 13 Jul 2020 22:30:02 +0300 Subject: [PATCH] Apply default value also when params is specified --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 4b098591..8e42b110 100644 --- a/index.js +++ b/index.js @@ -67,10 +67,17 @@ var supportedEncodingsNoDeflate = hasBrotliSupport function compression (options) { var opts = options || {} - if (hasBrotliSupport && opts.params === undefined) { - opts = objectAssign({}, opts) - opts.params = {} - opts.params[zlib.constants.BROTLI_PARAM_QUALITY] = 4 + if (hasBrotliSupport) { + // set the default level to a reasonable value with balanced speed/ratio + if (opts.params === undefined) { + opts = objectAssign({}, opts) + opts.params = {} + } + + if (opts.params[zlib.constants.BROTLI_PARAM_QUALITY] === undefined) { + opts.params = objectAssign({}, opts.params) + opts.params[zlib.constants.BROTLI_PARAM_QUALITY] = 4 + } } // options