pub fn parse_response_head<'a>(
input: &'a [u8],
limits: &Limits,
request_method: Method,
fields: &'a mut [FieldSpan],
) -> Result<Parsed<ParsedResponse<'a>>, HttpError>Expand description
Parses one response head from the start of input with the rules of
ClientConn, framed by the method of the request
it answers (a response to HEAD has no body; a 2xx to CONNECT is a
tunnel; any other method frames by the fields). Interim (1xx) heads are returned like any other; check
ResponseHead::is_informational and parse the next head after len.
No ClientLeniency applies, so obsolete line
folding is always HttpError::ObsFold. Allocates nothing.
§Errors
Every response parse error ClientConn::poll can return for a head
(UnexpectedEof aside), and HttpError::TooManyHeaders when the head
has more fields than fields holds.
§Examples
use http_net::{BodyFraming, FieldSpan, Limits, Method, Parsed, parse_response_head};
let input = b"HTTP/1.1 200 OK\r\nContent-Length: 100\r\n\r\n";
let mut fields = [FieldSpan::default(); 8];
let Parsed::Complete { head, .. } = parse_response_head(input, &Limits::new(), Method::Head, &mut fields)? else {
panic!("incomplete");
};
// A response to HEAD has no body, whatever its fields say.
assert_eq!(head.view().framing(), BodyFraming::None);
assert_eq!(head.view().content_length(), Some(100));