Skip to main content

decode_content_encoding

Function decode_content_encoding 

Source
pub fn decode_content_encoding(
    data: &[u8],
    content_encoding: Option<&str>,
    max_output_size: Option<usize>,
) -> Result<Vec<u8>>
Expand description

Decode an HTTP body per its Content-Encoding, or return it unchanged.

Handles the codings vgi-rpc speaks (zstd, gzip); the header may list several applied in order, which are decoded in reverse. identity and unknown codings are left as-is. Intended for an intermediary (proxy/gateway) that must read a compressed request/response body to inspect or rewrite it — see crate::intermediary for the framing helpers that go with it.

max_output_size caps the decompressed length of each coding, defending against zip-bomb-style payloads without first allocating the full result. At most MAX_CONTENT_CODINGS codings are applied, so total decode work stays bounded by that multiple of the cap rather than by attacker-chosen header length.

§Errors

Fails on a corrupt payload, a coding that decodes past max_output_size, or a header listing more than MAX_CONTENT_CODINGS codings.