Skip to main content

parse_request

Function parse_request 

Source
pub fn parse_request<'b, 'h>(
    buf: &'b [u8],
    hs: &'h mut [Header<'b>],
    lim: &Limits,
) -> Result<Status<Request<'b, 'h>>, Error>
Expand description

Parses a whole request head from the start of buf into hs.

Returns Partial until the head is complete; limits are enforced on partial input too. The parse never allocates. For input that arrives in pieces, RequestParser avoids parsing the same bytes again until a head can be complete.

Examples found in repository?
examples/bench_parse.rs (line 54)
52fn simoom(req: &[u8]) -> usize {
53    let mut hs = [EMPTY_HEADER; 32];
54    match parse_request(black_box(req), &mut hs, &Limits::default()) {
55        Ok(Status::Complete(r)) => r.head_len + r.headers.len(),
56        other => panic!("{other:?}"),
57    }
58}