Skip to main content

Crate sim_lib_net_core

Crate sim_lib_net_core 

Source
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§

HttpHead
A parsed HTTP response head: status line plus headers.
LineDecoder
Incremental newline framer.
NdjsonDecoder
Incremental newline-delimited JSON decoder.
ResponseHeadDemo
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.
HeadOutcome
The outcome of reading an HTTP head up to the \r\n\r\n terminator.
HttpBodyMode
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: chunked body.
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, applying default_path when the URL carries no path component.
parse_url_for_scheme_preserving_path
Parse a URL for a known scheme, resolving ws/wss default ports and preserving a caller-supplied trailing slash in the path.
read_capped_line
Read one line into buf, bounded to cap bytes.
read_head_until_double_crlf
Read an HTTP head byte-by-byte until the \r\n\r\n terminator, bounded to cap bytes.
response_head_demo
Build the modeled response-head parse report used by the cookbook recipe.