vibeio_http/hpack/mod.rs
1//! Primitives shared between HPACK (RFC 7541) and QPACK (RFC 9204).
2//!
3//! Both header-compression schemes use the same Huffman code
4//! (RFC 7541 Appendix B, reused verbatim by RFC 9204 Section 4.2) and the
5//! same prefix-integer representation (RFC 7541 Section 5.1, reused by
6//! RFC 9204 Section 4.3). These live here, one level up from the protocol
7//! modules that consume them, so neither codec needs to depend on the other.
8//!
9//! Consumers: `h2::hpack` (HPACK) and `h3::qpack` (QPACK).
10//!
11//! This module is also the public `vibeio_http::hpack` path: the HPACK
12//! codec surface (`Decoder`, `Encoder`, `Header`) is re-exported from
13//! `h2::hpack`.
14
15pub(crate) mod huffman;
16pub(crate) mod huffman_table;
17pub(crate) mod integer;
18
19#[cfg(feature = "h2")]
20pub use crate::h2::hpack::{Decoder, Encoder, Header};
21
22/// Errors produced by the shared HPACK/QPACK primitives.
23///
24/// The integer and Huffman variants are produced by the shared code; the
25/// remaining variants are produced by the HPACK decoder itself. Callers map
26/// these to protocol errors (`COMPRESSION_ERROR` for HTTP/2, the `0x2xx`
27/// QPACK error family for HTTP/3).
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29#[allow(clippy::enum_variant_names)]
30pub enum HpackError {
31 /// An integer representation overflowed or ran out of input.
32 InvalidInteger,
33 /// A string literal violated framing constraints.
34 InvalidString,
35 /// A Huffman-encoded string violated RFC 7541 Section 5.2 rules
36 /// (EOS symbol in the data, over-long or malformed padding, or
37 /// truncation).
38 InvalidHuffman,
39 /// An indexed header field referenced a non-existent table entry.
40 InvalidIndex,
41 /// A dynamic table size update exceeded the protocol maximum or
42 /// appeared after a header field representation.
43 InvalidMaxSize,
44 /// The decoded header list exceeded the configured maximum size.
45 HeaderListTooLarge,
46 /// The first octet of a representation matched no known pattern.
47 InvalidRepresentation,
48}