Skip to main content

H2ConnectionState

Struct H2ConnectionState 

Source
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: bool

Whether 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

Source

pub fn new() -> Self

Create a connection state with default limits.

Source

pub fn with_limits(limits: H2Limits) -> Self

Create a new H2ConnectionState with custom limits.

Source

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.

Source

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.

Source

pub fn has_completed(&self) -> bool

Check if any completed messages are ready to be popped.

Source

pub fn clear_buffer(&mut self)

Clear the internal buffer (e.g., when connection resets). Preserves HPACK decoder state for connection persistence.

Source

pub fn active_stream_count(&self) -> usize

Returns the number of active (incomplete) streams.

Source

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.

Trait Implementations§

Source§

impl Default for H2ConnectionState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more