http-lite

Crates.iohttp-lite
lib.rshttp-lite
version0.1.2
created_at2025-12-08 21:56:47.872173+00
updated_at2025-12-09 07:29:28.49672+00
descriptionno-std http request line parser (method, path, protocol)
homepage
repositoryhttps://github.com/spotthecow/http-lite/
max_upload_size
id1974434
size14,756
(spotthecow)

documentation

README

http-lite

ultra-lightweight http request line parser (like "GET /path HTTP/1.1") in no_std without alloc. It relies on heapless::String for a few things, which makes some call sites a little bit awkward, but it's not that bad and nothing leaves the stack. the library is still very young but will be updated. currently only support GET/POST and HTTP/1.1

Examples

parse request line

fn parse_request_line() {
    let line = "GET /submit HTTP/1.1";
    let parsed: RequestLine<32> = line.parse().unwrap();

    let mut target: String<32> = String::new();
    target.push_str("/submit").unwrap();

    let expected = RequestLine {
        method: crate::Method::GET,
        target,
        protocol: crate::Protocol::HTTP1,
    };

    assert_eq!(parsed, expected);
}

target is stored as unescaped ascii

fn request_line_with_params() {
    // notice "%20" in the raw string, and " " in the parsed target
    let line = "GET /submit?name=http%20lite HTTP/1.1";
    let parsed: RequestLine<32> = line.parse().unwrap();

    let mut target: String<32> = String::new();
    target.push_str("/submit?name=http lite").unwrap();

    let expected = RequestLine {
        method: crate::Method::GET,
        target,
        protocol: crate::Protocol::HTTP1,
    };

    assert_eq!(parsed, expected);
}

iterate query params

fn iterate_query_params() {
    // parse a request line string, reserving 64 bytes for the path ("/search?q=hi&land=en")
    // then get an iterator over the query params, reserving 16 bytes for each key and value
    let line: RequestLine<64> = "GET /search?q=hi&lang=en HTTP/1.1".parse().unwrap();
    let mut params = line.query_params::<16, 16>();

    let first = params.next().unwrap().unwrap();
    assert_eq!(first.k.as_str(), "q");
    assert_eq!(first.v.as_str(), "hi");

    let second = params.next().unwrap().unwrap();
    assert_eq!(second.k.as_str(), "lang");
    assert_eq!(second.v.as_str(), "en");

    assert!(params.next().is_none());
}
Commit count: 0

cargo fmt