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.
Multiple runtime libs share these parsers for wire framing, line accumulation, and head parsing while keeping transport and event mapping in their own layers.
§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_checked(b"a\nb")?, vec![b"a".to_vec()]);
assert_eq!(decoder.push_checked(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.
- Response
Head Demo - Report produced by the HTTP response-head cookbook recipe.
- 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.
Constants§
- DEFAULT_
MAX_ LINE_ BYTES - Default maximum line length for incremental stream decoders.
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.
- build_
http_ request_ head - Build a simple HTTP/1.1 request head.
- 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. - response_
head_ demo - Build the modeled response-head parse report used by the cookbook recipe.