Skip to main content

chain

Function chain 

Source
pub fn chain(
    body: &[u8],
    algos: &[Algorithm],
) -> Result<CompressedBody, CompressionError>
Expand description

Apply a sequence of compression algorithms in order, producing one set of body bytes + the joint Content-Encoding header.

The header value lists the algorithms in the order they were applied — per RFC 9110 §8.4, the LEFTMOST algorithm is the OUTERMOST wrapper, meaning a decoder must apply them right-to-left. So chain(body, [Gzip, Brotli]) produces a body that is gzip(brotli(body)) with header gzip, br.

Capped at MAX_CHAIN_LAYERS to prevent runaway misconfiguration.

§Errors

Returns CompressionError::ChainTooDeep when algos.len() > MAX_CHAIN_LAYERS, or the wrapped algorithm’s error if one of the encoders fails.