Expand description
Reusable, side-effect-free HTTP/streaming parsing and wire-format helpers.
This is a leaf parsing crate: it contains URL parsing, HTTP response-head parsing, body-mode classification, chunked-transfer decoding, line framing, and SSE/NDJSON record decoders, plus small text encoders for shared wire identifiers. It deliberately contains no socket/TLS I/O and no application policy – callers own transport and event mapping.
The behavior here was extracted from sim-lib-agent-runner-http so that
multiple runtime libs can share one tested implementation of the wire
framing rather than each hand-rolling line accumulation and head parsing.
§Example
LineDecoder frames newline-delimited input, buffering a partial final line
across pushes:
use sim_lib_net_core::LineDecoder;
let mut decoder = LineDecoder::new();
assert_eq!(decoder.push(b"a\nb"), vec![b"a".to_vec()]);
assert_eq!(decoder.push(b"c\n"), vec![b"bc".to_vec()]);Structs§
- Http
Head - A parsed HTTP response head: status line plus headers.
- Line
Decoder - Incremental newline framer.
- Ndjson
Decoder - Incremental newline-delimited JSON decoder.
- SseDecoder
- Incremental Server-Sent Events decoder.
- SseEvent
- A decoded Server-Sent Events record.
- UrlParts
- The structural components of an absolute URL.
Enums§
- CapOutcome
- The outcome of a single capped line read.
- Head
Outcome - The outcome of reading an HTTP head up to the
\r\n\r\nterminator. - Http
Body Mode - How the body following a response head should be read.
- NetError
- Errors produced by the net-core parsing primitives.
Statics§
- RECIPES
- Cookbook recipes for this lib, embedded at build time.
Functions§
- body_
mode - Classify how the body should be read, matching the client’s precedence.
- decode_
chunked - Decode a complete
Transfer-Encoding: chunkedbody. - hex_
encode - Encode bytes as lowercase hexadecimal text.
- parse_
http_ head - Parse a CRLF-delimited HTTP response head.
- parse_
url - Parse a
scheme://host[:port][/path]URL. - parse_
url_ for_ scheme - Parse a URL and require a specific
scheme, applyingdefault_pathwhen the URL carries no path component. - parse_
url_ for_ scheme_ preserving_ path - Parse a URL for a known
scheme, resolvingws/wssdefault ports and preserving a caller-supplied trailing slash in the path. - read_
capped_ line - Read one line into
buf, bounded tocapbytes. - read_
head_ until_ double_ crlf - Read an HTTP head byte-by-byte until the
\r\n\r\nterminator, bounded tocapbytes.