|
5 | 5 | [](https://github.com/neostandard/neostandard) |
6 | 6 |
|
7 | 7 | Adds compression utils to [the Fastify `reply` object](https://fastify.dev/docs/latest/Reference/Reply/#reply) and a hook to decompress requests payloads. |
8 | | -Supports `gzip`, `deflate`, and `brotli`. |
| 8 | +Supports `gzip`, `deflate`, `brotli`, and `zstd` (Node.js 22.15+/23.8+). |
9 | 9 |
|
10 | 10 | > ℹ️ Note: In large-scale scenarios, use a proxy like Nginx to handle response compression. |
11 | 11 |
|
@@ -37,11 +37,12 @@ This plugin adds two functionalities to Fastify: a compress utility and a global |
37 | 37 |
|
38 | 38 | Currently, the following encoding tokens are supported, using the first acceptable token in this order: |
39 | 39 |
|
40 | | -1. `br` |
41 | | -2. `gzip` |
42 | | -3. `deflate` |
43 | | -4. `*` (no preference — `@fastify/compress` will use `gzip`) |
44 | | -5. `identity` (no compression) |
| 40 | +1. `zstd` (Node.js 22.15+/23.8+) |
| 41 | +2. `br` |
| 42 | +3. `gzip` |
| 43 | +4. `deflate` |
| 44 | +5. `*` (no preference — `@fastify/compress` will use `gzip`) |
| 45 | +6. `identity` (no compression) |
45 | 46 |
|
46 | 47 | If an unsupported encoding is received or the `'accept-encoding'` header is missing, the payload will not be compressed. |
47 | 48 | To return an error for unsupported encoding, use the `onUnsupportedEncoding` option. |
@@ -175,6 +176,13 @@ await fastify.register( |
175 | 176 | // Only support gzip and deflate, and prefer deflate to gzip |
176 | 177 | { encodings: ['deflate', 'gzip'] } |
177 | 178 | ) |
| 179 | + |
| 180 | +// Example with zstd support (Node.js 22.15+/23.8+) |
| 181 | +await fastify.register( |
| 182 | + import('@fastify/compress'), |
| 183 | + // Prefer zstd, fallback to brotli, then gzip |
| 184 | + { encodings: ['zstd', 'br', 'gzip'] } |
| 185 | +) |
178 | 186 | ``` |
179 | 187 |
|
180 | 188 | ### brotliOptions and zlibOptions |
@@ -214,9 +222,10 @@ This plugin adds a `preParsing` hook to decompress the request payload based on |
214 | 222 |
|
215 | 223 | Currently, the following encoding tokens are supported: |
216 | 224 |
|
217 | | -1. `br` |
218 | | -2. `gzip` |
219 | | -3. `deflate` |
| 225 | +1. `zstd` (Node.js 22.15+/23.8+) |
| 226 | +2. `br` |
| 227 | +3. `gzip` |
| 228 | +4. `deflate` |
220 | 229 |
|
221 | 230 | If an unsupported encoding or invalid payload is received, the plugin throws an error. |
222 | 231 |
|
@@ -268,6 +277,13 @@ await fastify.register( |
268 | 277 | // Only support gzip |
269 | 278 | { requestEncodings: ['gzip'] } |
270 | 279 | ) |
| 280 | + |
| 281 | +// Example with zstd support for request decompression (Node.js 22.15+/23.8+) |
| 282 | +await fastify.register( |
| 283 | + import('@fastify/compress'), |
| 284 | + // Support zstd, brotli and gzip for request decompression |
| 285 | + { requestEncodings: ['zstd', 'br', 'gzip'] } |
| 286 | +) |
271 | 287 | ``` |
272 | 288 |
|
273 | 289 | ### forceRequestEncoding |
|
0 commit comments