pub struct H2ConnectionState {
pub preface_received: bool,
/* private fields */
}Expand description
Connection-level HTTP/2 state
Maintains HPACK decoder state and active stream tracking for a single HTTP/2 connection. Create one instance per direction (request/response) when parsing bidirectional traffic.
Use feed() to incrementally add data with timestamps, and try_pop()
to retrieve completed messages.
Fields§
§preface_received: boolWhether the HTTP/2 connection preface (PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n) has been received on this connection.
Implementations§
Source§impl H2ConnectionState
impl H2ConnectionState
Sourcepub fn with_limits(limits: H2Limits) -> Self
pub fn with_limits(limits: H2Limits) -> Self
Create a new H2ConnectionState with custom limits.
Sourcepub fn feed(
&mut self,
data: &[u8],
timestamp_ns: TimestampNs,
) -> Result<(), ParseError>
pub fn feed( &mut self, data: &[u8], timestamp_ns: TimestampNs, ) -> Result<(), ParseError>
Feed new data for incremental parsing with a timestamp.
The timestamp is used to track when frames arrive for latency
measurement. Call this method as data arrives, then use try_pop()
to retrieve completed messages.
Returns Ok(()) if data was processed (even if no messages completed yet). Returns Err only for fatal parse errors.
Sourcepub fn try_pop(&mut self) -> Option<(StreamId, ParsedH2Message)>
pub fn try_pop(&mut self) -> Option<(StreamId, ParsedH2Message)>
Pop a completed message if available.
Returns the stream_id and parsed message for a completed HTTP/2 stream. Messages are returned in the order they completed.
Sourcepub fn has_completed(&self) -> bool
pub fn has_completed(&self) -> bool
Check if any completed messages are ready to be popped.
Sourcepub fn clear_buffer(&mut self)
pub fn clear_buffer(&mut self)
Clear the internal buffer (e.g., when connection resets). Preserves HPACK decoder state for connection persistence.
Sourcepub fn active_stream_count(&self) -> usize
pub fn active_stream_count(&self) -> usize
Returns the number of active (incomplete) streams.
Sourcepub fn evict_stale_streams(&mut self, current_time_ns: TimestampNs)
pub fn evict_stale_streams(&mut self, current_time_ns: TimestampNs)
Evict stale streams that have exceeded the configured timeout.
Removes streams whose first frame arrived more than stream_timeout_ns
ago. If still over max_concurrent_streams after timeout eviction,
removes the oldest streams by first_frame_timestamp_ns.
Safety invariant: This only removes incomplete streams from
active_streams. Complete streams are removed at parse time (via
check_stream_completion) and moved to the completed queue before
eviction runs. Messages already popped via try_pop() are fully owned
by the caller and are unaffected by eviction.
Callers should invoke this periodically (e.g., during cleanup or after each parsing pass) to bound memory usage from incomplete streams.