1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Dynamic-table-aware HPACK encoder (RFC 7541 §6).
//!
//! Per-connection encoder owned by the H2 driver task. Each HEADERS block is encoded via
//! [`HpackEncoder::encode`] in a single synchronous pass at submission-pickup time. The
//! encoder is held by `&mut` on the driver — nothing else reaches it, so the table state
//! is just a plain field with no synchronization.
//!
//! ## Module layout
//!
//! - [`state`] — `TableState`, `insert`, FIFO eviction, reverse-index helpers.
//! - [`encode`] — the per-line decision walk and wire-format helpers.
//!
//! ## Distinct from QPACK
//!
//! HPACK has no encoder stream, no Known Received Count, no outstanding-section
//! pinning, no blocked-streams budget, and no Duplicate instruction. Inserts are
//! atomic with the field-line representation that triggers them (§6.2.1), and
//! references in a block are interpreted in order against the table state at that
//! point in the block.
use crateHeaderObserver;
use TableState;
use Arc;
/// Per-connection HPACK encoder.
///
/// Construct one per HTTP/2 connection (server or client). The operational table size
/// starts at 0 (encoder reduces to static-or-literal) until the peer's
/// `SETTINGS_HEADER_TABLE_SIZE` arrives via [`Self::set_protocol_max_size`]. At that
/// point, the operational size is raised to `min(local_preferred_size, peer_advertised)`
/// and a §6.3 Dynamic Table Size Update is queued for the next encode call (RFC 7541
/// §4.2). Subsequent peer SETTINGS changes flow through the same path.
///
/// This "wait for peer" posture differs from RFC 7541 §4.2's stated default of 4096
/// (we *could* use the dynamic table from frame zero) but mirrors QPACK's
/// peer-advertised-capacity model, removes a client-side race where pre-SETTINGS
/// HEADERS would be emitted assuming 4096 against a peer that intends to advertise
/// less, and unifies the mental model across HPACK and QPACK.
///
/// The cross-connection header observer is shared via `Arc` across all connections on
/// a listener; this encoder folds its per-connection observation accumulator into the
/// shared observer in [`Drop`].
pub