zstd
The zstd middleware compresses HTTP response bodies when the client sends Accept-Encoding: zstd. It uses a pure Go implementation and does not require CGO. It does not decompress request bodies.
Availability
The RoadRunner v3 bundle includes the Zstd plugin. Add zstd to http.middleware to enable it.
Configuration
Add zstd to the middleware list in your existing HTTP configuration:
version: "3"
http:
address: 127.0.0.1:8080
middleware: [ "zstd" ]The middleware does not require a separate configuration section. Eligible responses use Content-Encoding: zstd.
Put zstd before static or sendfile to compress their responses. See middleware order.
Compression behavior
Clients must request
zstdexplicitly with a nonzero quality value. Missing or unsupported encodings andzstd;q=0leave the response uncompressed.The default compression level is
zstd.SpeedFastest. The implementation reuses encoders through a pool.The normal minimum response size is 1,024 bytes. A flush can start compression below this limit.
The middleware skips HEAD requests, empty bodies, responses with an existing
Content-EncodingorContent-Range, and content types excluded by the compression library.The middleware adds
Vary: Accept-Encoding. It removes the originalContent-Lengthwhen it compresses a response.The compression library does not change ETags by default.
The middleware supports OpenTelemetry header propagation when RoadRunner tracing is active.
Using gzip and zstd
The zstd middleware does not provide gzip fallback. The gzip middleware is a separate plugin.
Documentation
Last updated