[−][src]Function http_bytes::parse_response_header
pub fn parse_response_header<'a, 'b>(
buf: &'a [u8],
headers_buffer: &'b mut [Header<'a>]
) -> Result<Option<(Response, &'a [u8])>, Error>
Parse this byte buffer into a Response
plus remaining trailing bytes.
Returns Ok(None)
if not enough bytes yet to produce a complete response.
If you need to get response header length, subtract length of returned buffer from length of original buffer.
let mut headers_buffer = vec![http_bytes::EMPTY_HEADER; 20]; let (r, b) = http_bytes::parse_response_header( b"HTTP/1.1 200 OK\r\n\ Host: example.com\r\n\ Content-Type: text/plain\r\n\ \r\n\ Hello, world\n", &mut headers_buffer[..], ).unwrap().unwrap(); assert_eq!(b, b"Hello, world\n"); assert_eq!(r.status(), http_bytes::http::StatusCode::OK); assert_eq!(r.headers().get(http_bytes::http::header::CONTENT_TYPE), Some(&http_bytes::http::header::HeaderValue::from_str("text/plain").unwrap()));