Skip to main content

Module compression

Module compression 

Source

Enums§

Encoding
A content coding rws can produce. Brotli and Zstd need the brotli and zstd features (both default); without them they are never chosen.
Level
How hard to compress.

Constants§

BROTLI_QUALITY
Brotli quality per Level.
DYNAMIC_PREFERENCE
Order of preference for responses compressed per request, when the client accepts several equally: zstd costs the least CPU at a ratio close to brotli’s at the levels used here.
MIN_COMPRESS_SIZE
Bodies smaller than this are sent uncompressed: gzip’s framing overhead and the CPU time outweigh what it saves (Caddy’s encode uses the same minimum).
STATIC_PREFERENCE
Order of preference for static files, compressed once per file version: brotli’s smaller output wins.
ZSTD_LEVEL
zstd level per Level.

Functions§

apply_compression
Like apply_gzip, with the content coding negotiated from the request’s Accept-Encoding among those compiled in (DYNAMIC_PREFERENCE): zstd, br or gzip. What the HTTP/1.1, HTTP/2 and HTTP/3 writers call (18.1.0).
apply_gzip
If the client accepts gzip and the response body is compressible text of at least MIN_COMPRESS_SIZE bytes, compress every content range in-place and add Content-Encoding: gzip; also appends Accept-Encoding to the Vary header. A body that gzip doesn’t make smaller (already compressed or random data) is left as it was, and so is a response that already has a Content-Encoding (e.g. a backend that compressed it).
encode
body in encoding at level; None if this build can’t produce it or the encoder fails.
mark_encoded
The headers of a body in encoding: Content-Encoding, and Accept-Encoding appended to Vary (or a new Vary).
negotiate
The coding to use for this request among preference (in that order of preference on equal weight): the one with the highest q in its Accept-Encoding, counting * for codings not listed; None without the header, or when nothing in preference is acceptable or compiled in.