Skip to main content

Module brotli

Module brotli 

Source
Expand description

The brotli node — compresses the response body with brotli when the client accepts it and the response matches the configured content types and minimum size. Port of APISIX’s brotli plugin (response-phase: place after upstream, before client).

Shares its gating helpers (Accept-Encoding parsing, content-type matching, already-encoded detection) with the gzip node; featherbit performs the Accept-Encoding check explicitly since there is no nginx below the gateway to do it.

Deviations from APISIX:

  • mode, lgwin, lgblock, and http_version are not supported — content_codec uses generic mode with its own window size, and responses are fully buffered.
  • min_length is compared against the actual buffered body length, not the upstream Content-Length header.

Structs§

BrotliPlugin
Compresses Context.response.body with brotli, sets content-encoding: br, drops the stale content-length, and downgrades a strong ETag to a weak one (as APISIX does — the compressed bytes are not byte-identical to the original representation). Skipped (pure passthrough) when the client does not accept br, the response is already content-encoded, the content type does not match, or the body is shorter than min_length. This plugin never fails at execution time — a codec error logs a warning and leaves the response untouched.

Functions§

weaken_etag 🔒
Mirrors APISIX’s weak_etag_header: a strong quoted etag ("abc") becomes weak (W/"abc"), a weak etag is kept, and a non-standard (unquoted) etag is dropped since it cannot be weakened.