@fastify/compress 7.0.1 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -15
- package/package.json +3 -3
- package/test/global-compress.test.js +152 -80
- package/test/routes-compress.test.js +21 -10
package/index.js
CHANGED
|
@@ -242,7 +242,6 @@ function buildRouteCompress (fastify, params, routeOptions, decorateOnly) {
|
|
|
242
242
|
// response is already compressed
|
|
243
243
|
return next()
|
|
244
244
|
}
|
|
245
|
-
setVaryHeader(reply)
|
|
246
245
|
|
|
247
246
|
let stream, encoding
|
|
248
247
|
const noCompress =
|
|
@@ -280,11 +279,11 @@ function buildRouteCompress (fastify, params, routeOptions, decorateOnly) {
|
|
|
280
279
|
payload = intoStream(payload)
|
|
281
280
|
}
|
|
282
281
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
282
|
+
setVaryHeader(reply)
|
|
283
|
+
reply.header('Content-Encoding', encoding)
|
|
284
|
+
if (params.removeContentLengthHeader) {
|
|
285
|
+
reply.removeHeader('content-length')
|
|
286
|
+
}
|
|
288
287
|
|
|
289
288
|
stream = zipStream(params.compressStream, encoding)
|
|
290
289
|
pump(payload, stream, onEnd.bind(reply))
|
|
@@ -360,7 +359,6 @@ function compress (params) {
|
|
|
360
359
|
return
|
|
361
360
|
}
|
|
362
361
|
|
|
363
|
-
setVaryHeader(this)
|
|
364
362
|
let stream, encoding
|
|
365
363
|
const noCompress =
|
|
366
364
|
// don't compress on x-no-compression header
|
|
@@ -405,11 +403,11 @@ function compress (params) {
|
|
|
405
403
|
payload = intoStream(payload)
|
|
406
404
|
}
|
|
407
405
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
406
|
+
setVaryHeader(this)
|
|
407
|
+
this.header('Content-Encoding', encoding)
|
|
408
|
+
if (params.removeContentLengthHeader) {
|
|
409
|
+
this.removeHeader('content-length')
|
|
410
|
+
}
|
|
413
411
|
|
|
414
412
|
stream = zipStream(params.compressStream, encoding)
|
|
415
413
|
pump(payload, stream, onEnd.bind(this))
|
|
@@ -419,9 +417,10 @@ function compress (params) {
|
|
|
419
417
|
|
|
420
418
|
function setVaryHeader (reply) {
|
|
421
419
|
if (reply.hasHeader('Vary')) {
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
420
|
+
const rawHeaderValue = reply.getHeader('Vary')
|
|
421
|
+
const headerValueArray = Array.isArray(rawHeaderValue) ? rawHeaderValue : [rawHeaderValue]
|
|
422
|
+
if (!headerValueArray.some((h) => h.includes('accept-encoding'))) {
|
|
423
|
+
reply.header('Vary', headerValueArray.concat('accept-encoding').join(', '))
|
|
425
424
|
}
|
|
426
425
|
} else {
|
|
427
426
|
reply.header('Vary', 'accept-encoding')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/compress",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Fastify compression utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@fastify/pre-commit": "^2.0.2",
|
|
20
20
|
"@types/node": "^20.4.2",
|
|
21
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
22
|
-
"@typescript-eslint/parser": "^
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
22
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
23
23
|
"adm-zip": "^0.5.10",
|
|
24
24
|
"fastify": "^4.19.2",
|
|
25
25
|
"jsonstream": "^1.0.3",
|