Skip to main content

sim_lib_net_core/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(missing_docs)]
3//! Reusable, side-effect-free HTTP/streaming parsing and wire-format helpers.
4//!
5//! This is a leaf parsing crate: it contains URL parsing, HTTP response-head
6//! parsing, body-mode classification, chunked-transfer decoding, line framing,
7//! and SSE/NDJSON record decoders, plus small text encoders for shared wire
8//! identifiers. It deliberately contains **no** socket/TLS I/O and **no**
9//! application policy -- callers own transport and event mapping.
10//!
11//! The behavior here was extracted from `sim-lib-agent-runner-http` so that
12//! multiple runtime libs can share one tested implementation of the wire
13//! framing rather than each hand-rolling line accumulation and head parsing.
14//!
15//! # Example
16//!
17//! `LineDecoder` frames newline-delimited input, buffering a partial final line
18//! across pushes:
19//!
20//! ```
21//! use sim_lib_net_core::LineDecoder;
22//!
23//! let mut decoder = LineDecoder::new();
24//! assert_eq!(decoder.push(b"a\nb"), vec![b"a".to_vec()]);
25//! assert_eq!(decoder.push(b"c\n"), vec![b"bc".to_vec()]);
26//! ```
27
28mod body;
29mod error;
30mod hex;
31mod http;
32mod line;
33mod ndjson;
34mod read;
35mod sse;
36mod url;
37
38pub use body::decode_chunked;
39pub use error::NetError;
40pub use hex::hex_encode;
41pub use http::{HttpBodyMode, HttpHead, body_mode, parse_http_head};
42pub use line::LineDecoder;
43pub use ndjson::NdjsonDecoder;
44pub use read::{CapOutcome, HeadOutcome, read_capped_line, read_head_until_double_crlf};
45pub use sse::{SseDecoder, SseEvent};
46pub use url::{UrlParts, parse_url, parse_url_for_scheme, parse_url_for_scheme_preserving_path};
47
48/// Cookbook recipes for this lib, embedded at build time.
49pub static RECIPES: sim_cookbook::EmbeddedDir =
50    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));
51
52#[cfg(test)]
53mod tests;