Stateful HTTP/2 frame parser with HPACK support for passive traffic monitoring.
This crate decodes HTTP/2 frames and HPACK-compressed headers from raw
byte streams, maintaining per-connection decoder state so that dynamic
table entries are preserved across successive feed() calls.
Key types
- [
H2SessionCache] — thread-safe cache of many connections keyed by an arbitraryK. Best when you have many connections and want automatic state management. - [
H2ConnectionState] — state for a single HTTP/2 connection. Usefeed()to push data incrementally andtry_pop()to retrieve completed messages.
Examples
Multi-connection cache
use h2session::{H2SessionCache, ParsedH2Message};
let cache = H2SessionCache::<u64>::new();
// Parse a buffer for connection 42
let completed = cache.parse(42, &raw_bytes).unwrap();
for (stream_id, msg) in &completed {
if msg.is_request() {
println!(
"{} {}",
msg.method.as_deref().unwrap_or("?"),
msg.path.as_deref().unwrap_or("/")
);
}
}
# let raw_bytes: Vec<u8> = vec![];
Single-connection incremental parsing
use h2session::{H2ConnectionState, TimestampNs};
let mut state = H2ConnectionState::new();
// Feed data as it arrives
state.feed(&chunk, TimestampNs(0)).unwrap();
// Pop completed messages
while let Some((stream_id, msg)) = state.try_pop() {
println!("stream {stream_id}: request={}", msg.is_request());
}
# let chunk: Vec<u8> = vec![];
Feature flags
tracing— emittracing::warn!events for non-fatal parse issues (stale stream eviction, etc.)