gzip, deflate, brotli, or zstd based on the client’s Accept-Encoding header.
Bodies smaller than 200 bytes remain uncompressed because compression would likely increase their size and waste CPU cycles. See the fasthttp source.
Behavior
- Skips compression for responses that already define
Content-Encoding, for range requests,206responses, status codes without bodies, or when either side sendsCache-Control: no-transform HEADrequests negotiate compression soContent-Encoding,Content-Length,ETag, andVaryreflect the encoded representation, but the body is removed before sending- When compression runs, strong
ETagvalues are recomputed from the compressed bytes; when skipped,Accept-Encodingis still merged intoVaryunless the header is*or already present
Signatures
Usage
Basic Example
Skip Specific Routes
Configuration
Skips this middleware when the function returns
true.Compression level to use. Available levels:
LevelDisabled (-1): Compression is disabledLevelDefault (0): Default compression levelLevelBestSpeed (1): Best compression speedLevelBestCompression (2): Best compression