Skip to main content

Crate simoom_hpack

Crate simoom_hpack 

Source
Expand description

HPACK (RFC 7541) for simoom.

  • Decoder: decodes header blocks into a callback, with a cap on the dynamic table size (the value we advertise in SETTINGS_HEADER_TABLE_SIZE) and on the decoded header list size. Literal strings that are not Huffman coded are passed straight from the input; Huffman strings are decoded into two reusable scratch buffers, and the dynamic table keeps all entries in one byte buffer, so steady-state decoding does not allocate.
  • Encoder: indexes repeated fields, never indexes sensitive ones (authorization, proxy-authorization, cookie, set-cookie), and does not index fields whose values are usually unique (content-length, etag, validators, :path with a query).
  • huffman: table-driven Huffman decoding, four bits per step, and encoding.
use simoom_hpack::{Decoder, Encoder};
let mut enc = Encoder::new(4096);
let mut dec = Decoder::new(4096, 16 * 1024);
let mut block = Vec::new();
enc.encode(&[(b":method", b"GET"), (b"x-id", b"42")], &mut block);
let mut got = Vec::new();
dec.decode(&block, &mut |n: &[u8], v: &[u8]| got.push((n.to_vec(), v.to_vec()))).unwrap();
assert_eq!(got[1], (b"x-id".to_vec(), b"42".to_vec()));

Modules§

huffman
HPACK Huffman coding (RFC 7541 §5.2 and Appendix B).

Structs§

Decoder
A stateful header block decoder.
Encoder
A stateful header block encoder.

Enums§

Error
HPACK decoding errors. Every error except Error::HeaderListTooLarge leaves the decoder out of step with the peer’s encoder and maps to the HTTP/2 connection error COMPRESSION_ERROR.

Constants§

DEFAULT_TABLE_SIZE
The protocol’s initial dynamic table size (RFC 7541 §4.2, RFC 9113 §6.5.2).

Statics§

STATIC_TABLE
The static table, 1-based in the protocol (index i is STATIC_TABLE[i - 1]).

Functions§

bytes_eq
Byte-slice equality for short strings, done with word loads instead of a memcmp call (header names and values are mostly under 32 bytes).
decode_integer
Decodes an N-bit prefix integer at buf[*pos]. At most four continuation bytes are accepted (values up to about 2^28), far above anything a header block can carry.
encode_integer
Encodes value with an N-bit prefix (RFC 7541 §5.1); first holds the high bits of the first byte.
encode_string
Encodes a string literal, Huffman coded when that is shorter and huffman is set.
field_size
Size of a header field for table and list accounting: name + value + 32 (RFC 7541 §4.1).
is_sensitive
Fields whose values must never enter a compression context (RFC 7541 §7.1.3): they are sent as never-indexed literals, so intermediaries keep them out of their tables too.