@fastify/compress 8.3.0 → 8.3.1

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
@@ -447,7 +447,7 @@ function compress (params) {
447
447
 
448
448
  stream = zipStream(params.compressStream, encoding)
449
449
  pump(payload, stream, onEnd.bind(this))
450
- this.send(stream)
450
+ return this.send(stream)
451
451
  }
452
452
  }
453
453
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/compress",
3
- "version": "8.3.0",
3
+ "version": "8.3.1",
4
4
  "description": "Fastify compression utils",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const zlib = require('node:zlib')
5
+ const Fastify = require('fastify')
6
+ const fastifyCompress = require('../..')
7
+
8
+ const largeJsonString = JSON.stringify({
9
+ text: 'Lorem ipsum dolor sit amet. '.repeat(2048),
10
+ })
11
+
12
+ async function routes (fastify) {
13
+ fastify.route({
14
+ method: 'GET',
15
+ url: '/api/compress-test',
16
+ handler: async function (_request, reply) {
17
+ reply.type('application/json')
18
+ return reply.compress(largeJsonString)
19
+ }
20
+ })
21
+ }
22
+
23
+ test('should compress large payload without premature close', async (t) => {
24
+ const fastify = Fastify()
25
+ await fastify.register(fastifyCompress, { encodings: ['gzip'], global: true })
26
+ await fastify.register(routes)
27
+
28
+ const response = await fastify.inject({
29
+ url: '/api/compress-test',
30
+ method: 'GET',
31
+ headers: { 'accept-encoding': 'gzip' }
32
+ })
33
+
34
+ t.assert.equal(response.statusCode, 200)
35
+ t.assert.equal(response.headers['content-encoding'], 'gzip')
36
+ t.assert.ok(
37
+ response.rawPayload.length > 0,
38
+ `Expected compressed response body, got ${response.rawPayload.length} bytes`
39
+ )
40
+
41
+ const decompressed = zlib.gunzipSync(response.rawPayload)
42
+ t.assert.equal(decompressed.toString('utf-8'), largeJsonString)
43
+ })