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.
The RoadRunner v3 bundle includes the Zstd plugin. Add zstd to http.middleware to enable it.
Add zstd to the middleware list in your existing HTTP configuration:
{% code title=".rr.yaml" %}
version: "3"
http:
address: 127.0.0.1:8080
middleware: [ "zstd" ]{% endcode %}
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.
- 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.
The zstd middleware does not provide gzip fallback. The gzip middleware is a separate plugin.
{% hint style="warning" %} If both gzip and zstd middleware are enabled, their order can determine the selected encoding. The separate plugins do not compare quality values with each other. Do not expect them to select the encoding with the highest quality value across both plugins. {% endhint %}