http-collator 0.2.1

Collates raw network data events into complete HTTP request/response exchanges
Documentation

HTTP collation library

Collates individual data events (from eBPF, pcap, etc.) into complete HTTP request/response exchanges. Supports both HTTP/1.x and HTTP/2.

Usage

Implement the [DataEvent] trait for your data source, then feed events to the [Collator]:

use http_collator::{Collator, CollationEvent, DataEvent, Direction};
use bytes::Bytes;

struct MyEvent {
    payload: Vec<u8>,
    timestamp_ns: u64,
    direction: Direction,
    connection_id: u64,
    process_id: u32,
    remote_port: u16,
}

impl DataEvent for MyEvent {
    fn payload(&self) -> &[u8] { &self.payload }
    fn timestamp_ns(&self) -> u64 { self.timestamp_ns }
    fn direction(&self) -> Direction { self.direction }
    fn connection_id(&self) -> u64 { self.connection_id }
    fn process_id(&self) -> u32 { self.process_id }
    fn remote_port(&self) -> u16 { self.remote_port }
}

let collator = Collator::<MyEvent>::new();
# let my_event = MyEvent { payload: vec![], timestamp_ns: 0, direction: Direction::Write, connection_id: 1, process_id: 1, remote_port: 80 };
for event in collator.add_event(my_event) {
    match event {
        CollationEvent::Message { message, metadata } => {
            println!("parsed message for conn {}", metadata.connection_id);
        }
        CollationEvent::Exchange(exchange) => {
            println!("complete exchange: {exchange}");
        }
    }
}