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 inSETTINGS_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,:pathwith 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§
Enums§
- Error
- HPACK decoding errors. Every error except
Error::HeaderListTooLargeleaves the decoder out of step with the peer’s encoder and maps to the HTTP/2 connection errorCOMPRESSION_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
iisSTATIC_TABLE[i - 1]).
Functions§
- bytes_
eq - Byte-slice equality for short strings, done with word loads instead of a
memcmpcall (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
valuewith an N-bit prefix (RFC 7541 §5.1);firstholds the high bits of the first byte. - encode_
string - Encodes a string literal, Huffman coded when that is shorter and
huffmanis 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.