Skip to main content

select_zstd_dict_for_response

Function select_zstd_dict_for_response 

Source
pub fn select_zstd_dict_for_response<'a>(
    response_headers: &HashMap<String, String>,
    loaded_dicts: &'a HashMap<String, Vec<u8>>,
) -> Result<Option<&'a [u8]>, CodecZstdDictError>
Expand description

Pick the zstd dict to decompress this response with.

§Parameters

  • response_headers: HTTP response header map. Keys are looked up case-insensitively, matching the way reqwest::HeaderMap and most HTTP libraries treat headers on the wire.
  • loaded_dicts: { "sha256:<hex>" -> dict bytes }. Populate this from your tokenizer map’s zstd_dictionaries[] entries; keys follow the same canonical shape the server emits.

§Returns

  • Ok(Some(&dict_bytes)) when the response is Content-Encoding: zstd and the server’s Codec-Zstd-Dict header points at a loaded dict — pass these bytes to your zstd decoder (e.g. zstd::stream::Decoder::with_dictionary).
  • Ok(None) when the response isn’t zstd. The caller should pass the body through identity / let its HTTP stack auto-decompress gzip / brotli.

§Errors

Returns CodecZstdDictError when the response is zstd but the header is missing, malformed, or names a dict the client hasn’t loaded. Wrong-dict decompression is never attempted — see the spec rationale at spec/PROTOCOL.md.