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//! Multiple runtime libs share these parsers for wire framing, line
12//! accumulation, and head parsing while keeping transport and event mapping in
13//! their own layers.
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_checked(b"a\nb")?, vec![b"a".to_vec()]);
25//! assert_eq!(decoder.push_checked(b"c\n")?, vec![b"bc".to_vec()]);
26//! # Ok::<(), sim_lib_net_core::NetError>(())
27//! ```
28
29mod body;
30mod cookbook;
31mod error;
32mod hex;
33mod http;
34mod line;
35mod ndjson;
36mod read;
37mod sse;
38mod url;
39
40pub use body::decode_chunked;
41pub use cookbook::{ResponseHeadDemo, response_head_demo};
42pub use error::NetError;
43pub use hex::hex_encode;
44pub use http::{HttpBodyMode, HttpHead, body_mode, build_http_request_head, parse_http_head};
45pub use line::{DEFAULT_MAX_LINE_BYTES, LineDecoder};
46pub use ndjson::NdjsonDecoder;
47pub use read::{CapOutcome, HeadOutcome, read_capped_line, read_head_until_double_crlf};
48pub use sse::{SseDecoder, SseEvent};
49pub use url::{UrlParts, parse_url, parse_url_for_scheme, parse_url_for_scheme_preserving_path};
50
51/// Cookbook recipes for this lib, embedded at build time.
52pub static RECIPES: sim_cookbook::EmbeddedDir =
53    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));
54
55#[cfg(test)]
56mod tests;