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() {
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() {
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());
}