Repository navigation
Closed
Description
Phase 2 of issue #8. Adds Brotli (br) and zstd (zstd) backends through the
already-shipped http_encoder_t vtable. No architectural changes — phase 1
specifically built the registry, negotiation, response pipeline and request
decoder to take additional codecs as drop-ins.
Scope
- Brotli —
libbrotlienc(encode) +libbrotlidec(decode). Optional at
build time via pkg-config;--disable-brotliopts out. Default level 4
(production-typical; level 11 is research-quality but ~50× slower). - zstd —
libzstd. Optional;--disable-zstdopts out. Default level 3
(the zstd team's own production default). - Negotiation: extend the parser with
br/zstdrecognition; preference
order at select time zstd > brotli > gzip (matches typical server policy).
q=0 rejection still wins per-codec. - Inbound decoding:
Content-Encoding: brandzstddecoded transparently,
same anti-bomb cap as gzip; unknown codings still 415.
Config
Per-codec level setters on HttpServerConfig, frozen at server construction:
| Setter | Default | Range |
|---|---|---|
setBrotliLevel(int) |
4 | 0..11 |
setZstdLevel(int) |
3 | 1..22 |
setCompressionLevel keeps its gzip-only meaning. Universal interpretation
considered and rejected — codec level scales differ enough that linear mapping
loses the high end of brotli/zstd.
Out of scope
- Pre-compressed static assets (
*.br/*.zston disk via sendfile) —
phase 3, requires file-serving rework. - q-value-based client preference. Server-side preference order covers ~99%
of real Accept-Encoding strings; honouring client q-values exactly would
require storing q as a number (not bool) in the parser. Tracked but
not in this phase. - Threadpool offload for very large bodies. Inline encoding measured first.
Implementation plan
- build + brotli backend — pkg-config detection,
http_compression_brotli.c
implementing the encoder vtable + a brotli decoder for inbound. - build + zstd backend — same shape for
libzstd. - negotiation extension — add
br/zstdtoken recognition + the
preference-order select; unit tests for both new codings. - config knobs —
setBrotliLevel/setZstdLevelsetters, frozen-snapshot
plumbing, phpt for setter validation + locked-config guard. - wiring + phpt — integrate both codecs into the existing apply_buffered /
stream wrapper / decode paths (no changes there if the registry lookup
succeeds for the chosen codec); H1 buffered round-trip phpt per codec. - docs — extend
docs/COMPRESSION.md, CHANGELOG entry.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
feat(compression): Brotli + zstd backends (issue #9)
EdmondDantes commentedon May 6, 2026
Shipped in 409685d on main. Brotli + zstd plug into the phase-1
http_encoder_tvtable; preference orderzstd > br > gzip > identity; newsetBrotliLevel/setZstdLevel/getSupportedEncodings(); compression coverage 80.4% → 82.9%.chore(static): yellow cleanups (#8/#9/#12/#13/#15)