Skip to main content

base_http1/
lib.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4//! HTTP/1 framing over independently owned scheduler I/O lanes.
5//! No runtime, tasks or transport ownership are hidden inside this crate.
6#![doc = include_str!("../readme.md")]
7#![forbid(unsafe_code)]
8
9mod client;
10mod error;
11mod input;
12#[cfg(any(test, fuzzing))]
13mod oracle;
14mod output;
15mod parse;
16mod wire;
17
18pub use client::{RequestWriter, ResponseReader};
19pub use error::Error;
20pub use input::{Exchange, IncomingBody, RequestReader};
21pub use output::{InterimWriter, ResponseWriter};
22
23/// Compare the request head parser with the previous httparse pipeline,
24/// panicking when they disagree. Only fuzz targets build this.
25#[cfg(fuzzing)]
26#[doc(hidden)]
27pub fn fuzz_request_head(bytes: &[u8]) {
28    oracle::compare(bytes, 8);
29}
30
31/// Compare the response head parser with the previous httparse pipeline.
32#[cfg(fuzzing)]
33#[doc(hidden)]
34pub fn fuzz_response_head(bytes: &[u8]) {
35    oracle::compare_response(bytes, 8);
36}
37
38/// Compare the trailer section parser with the previous line reader.
39#[cfg(fuzzing)]
40#[doc(hidden)]
41pub fn fuzz_trailers(bytes: &[u8]) {
42    oracle::compare_trailers(bytes, 8);
43}
44
45/// Bounds apply before allocating or accepting an entire wire section.
46#[derive(Clone, Debug)]
47pub struct Options {
48    pub max_head_bytes: usize,
49    pub max_fields: usize,
50    pub max_chunk_line_bytes: usize,
51    pub read_size: usize,
52}
53
54impl Default for Options {
55    fn default() -> Self {
56        Self {
57            max_head_bytes: 32 * 1024,
58            max_fields: 100,
59            max_chunk_line_bytes: 4096,
60            read_size: 16 * 1024,
61        }
62    }
63}
64
65impl Options {
66    pub fn validate(&self) -> Result<(), Error> {
67        if self.max_head_bytes < 4
68            || self.max_fields == 0
69            || self.max_chunk_line_bytes < 2
70            || self.read_size == 0
71        {
72            return Err(Error::Invalid("invalid HTTP/1 limits"));
73        }
74        Ok(())
75    }
76}