[][src]Function http_bytes::parse_request_header

pub fn parse_request_header<'a, 'b>(
    buf: &'a [u8],
    headers_buffer: &'b mut [Header<'a>],
    scheme: Option<Scheme>
) -> Result<Option<(Request, &'a [u8])>, Error>

Parse this byte buffer into a Request plus remaining trailing bytes.

Returns Ok(None) if not enough bytes yet to produce a complete request.

If you need to get request header length, subtract length of returned buffer from length of original buffer.

If scheme is specified then information from Host: header is filled in into URI, if it exists. In case of no host header the URI would be scheme-less.

If default Cargo feature basicauth is enabled and Authorization: Basic HTTP header is found, it is also filled in into URI, if there is schema and host.

let mut headers_buffer = vec![http_bytes::EMPTY_HEADER; 20];
let (r, b) = http_bytes::parse_request_header(
    b"GET /ololo HTTP/1.1\r\n\
      Host: example.com\r\n\
      Authorization: Basic cm1zOnJtcw==\r\n\
      user-agent: unittest\r\n\
      \r\n",
    &mut headers_buffer[..],
    Some(http_bytes::http::uri::Scheme::HTTP),
).unwrap().unwrap();
assert_eq!(b, b"");
assert_eq!(r.method(), http_bytes::http::method::Method::GET);
let mut u = "http://example.com/ololo";
#[cfg(feature="basicauth")] { u = "http://rms:rms@example.com/ololo"; }
assert_eq!(r.uri(), &u.parse::<http_bytes::http::uri::Uri>().unwrap());
assert_eq!(r.headers().get(http_bytes::http::header::USER_AGENT),
    Some(&http_bytes::http::header::HeaderValue::from_str("unittest").unwrap()));