> For the complete documentation index, see [llms.txt](https://docs.roadrunner.dev/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roadrunner.dev/docs/http/zstd.md).

# 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:

{% code title=".rr.yaml" %}

```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](/docs/http/http.md#middleware-order).

## Compression behavior

* Clients must request `zstd` explicitly with a nonzero quality value. Missing or unsupported encodings and `zstd;q=0` leave 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-Encoding` or `Content-Range`, and content types excluded by the compression library.
* The middleware adds `Vary: Accept-Encoding`. It removes the original `Content-Length` when 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](/docs/http/gzip.md) 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 %}

## Documentation

* [Zstd middleware plugin](https://github.com/roadrunner-server/zstd)
* [Zstd middleware PR #1](https://github.com/roadrunner-server/zstd/pull/1)
* [MDN Accept-Encoding header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept-Encoding)
* [HTTP response streaming](/docs/http/resp-streaming.md)
