@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 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
- params.removeContentLengthHeader
284
- ? reply
285
- .header('Content-Encoding', encoding)
286
- .removeHeader('content-length')
287
- : reply.header('Content-Encoding', encoding)
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
- params.removeContentLengthHeader
409
- ? this
410
- .header('Content-Encoding', encoding)
411
- .removeHeader('content-length')
412
- : this.header('Content-Encoding', encoding)
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 varyHeader = Array.isArray(reply.getHeader('Vary')) ? reply.getHeader('Vary') : [reply.getHeader('Vary')]
423
- if (!varyHeader.some((h) => h.includes('accept-encoding'))) {
424
- reply.header('Vary', `${varyHeader.join(', ')}, accept-encoding`)
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.1",
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": "^6.0.0",
22
- "@typescript-eslint/parser": "^6.0.0",
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",