# 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
```rs
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
```rs
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
```rs
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());
}
```