Skip to main content

Module http

Module http 

Source
Available on crate feature http only.
Expand description

Passive HTTP/1.x observer.

Bridges httparse’s zero-copy parser into flowscope’s SessionParser abstraction. Receives bytes from the per-flow TCP stream, emits parsed HttpRequest / HttpResponse events as HttpMessage variants.

§Quick start

use flowscope::extract::FiveTuple;
use flowscope::http::{HttpMessage, HttpParser};
use flowscope::{FlowSessionDriver, SessionEvent, SessionParser, Timestamp};

let _driver = FlowSessionDriver::new(
    FiveTuple::bidirectional(),
    HttpParser::default(),
);

For a callback-shaped interface, drive a SessionParser from a consumer loop — Application events carry the parsed HttpMessage directly:

for view in views() {
    for ev in driver.track(view) {
        if let SessionEvent::Application { message, .. } = ev {
            match message {
                HttpMessage::Request(r)  => { /* handle request */ }
                HttpMessage::Response(r) => { /* handle response */ }
            }
        }
    }
}

§Scope

  • HTTP/1.0 and HTTP/1.1.
  • Request line + headers + body via Content-Length.
  • Pipelined requests on one connection.
  • HTTP/2 / HTTP/3: out of scope.
  • Chunked Transfer-Encoding: deferred.

§Convenience accessors

Every header accessor below skips the boilerplate of “iterate the headers: Vec<(String, Vec<u8>)>, case-insensitive compare, then from_utf8”. They cover the headers every HTTP-monitor example reached for.

§HttpRequest

MethodReturnsEquivalent
hostOption<&str>first Host header
user_agentOption<&str>first User-Agent
cookieOption<&str>first Cookie
content_typeOption<&str>Content-Type (new in 0.10)
content_lengthOption<u64>parsed Content-Length (new in 0.10)
refererOption<&str>Referer (new in 0.10)
acceptOption<&str>Accept (new in 0.10)
headerOption<&[u8]>first matching header (case-insensitive)
headers_allimpl Iterator<Item = &[u8]>every matching header

§HttpResponse

MethodReturnsEquivalent
status_classOption<u8>status / 100 (new in 0.10)
is_successbool2xx (new in 0.10)
is_redirectbool3xx (new in 0.10)
is_client_errorbool4xx (new in 0.10)
is_server_errorbool5xx (new in 0.10)
content_typeOption<&str>Content-Type
content_lengthOption<u64>parsed Content-Length
set_cookieimpl Iterator<Item = &str>every Set-Cookie header
headerOption<&[u8]>first matching header
headers_allimpl Iterator<Item = &[u8]>every matching header

Structs§

HttpConfig
Configuration knobs for the HTTP parser.
HttpExchange
One HTTP request + response pair.
HttpExchangeParser
SessionParser impl that emits one HttpExchange per request/response pair.
HttpParser
Per-flow HTTP/1.x parser. Holds independent state for the initiator (request) and responder (response) directions.
HttpRequest
Parsed HTTP/1.x request — start line + headers + body.
HttpResponse
Parsed HTTP/1.x response.

Enums§

HttpMessage
Unified message type emitted by HttpParser.
HttpOutcome
Outcome of an observed HTTP exchange.
HttpVersion

Constants§

PARSER_KIND
Slug returned by HttpParser’s parser_kind(). Use at match sites in place of a string literal so typos fail to resolve instead of silently miss. Available also as flowscope::parser_kinds::HTTP.