pub struct ResponseHead<'a> { /* private fields */ }Expand description
A parsed response head, borrowed from the client connection’s buffer.
§Examples
use http_net::{ClientConn, ClientEvent, Request};
let mut conn = ClientConn::new();
let mut out = Vec::new();
conn.send_request(&Request::get("/").header("host", "a"), &mut out).unwrap();
let _ = conn.feed(b"HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n");
let ClientEvent::Response(resp) = conn.poll().unwrap() else { panic!() };
assert_eq!(resp.status(), 404);
assert_eq!(resp.reason(), "Not Found");Implementations§
Source§impl<'a> ResponseHead<'a>
impl<'a> ResponseHead<'a>
Sourcepub fn reason(&self) -> &'a str
pub fn reason(&self) -> &'a str
The reason phrase, if it is UTF-8 (it carries no meaning; RFC 9112
tells clients to ignore it). Empty for a status line without one,
including HTTP/1.1 200 with no space after the code.
§Examples
assert_eq!(resp.reason(), "");Sourcepub fn header(&self, name: &str) -> Option<&'a [u8]>
pub fn header(&self, name: &str) -> Option<&'a [u8]>
The value of the first field named name (ASCII case-insensitive).
§Examples
assert_eq!(resp.header("content-type"), Some(&b"text/plain"[..]));Sourcepub fn header_str(&self, name: &str) -> Option<&'a str>
pub fn header_str(&self, name: &str) -> Option<&'a str>
Sourcepub fn header_all<'n>(&self, name: &'n str) -> HeaderValues<'a, 'n> ⓘ
pub fn header_all<'n>(&self, name: &'n str) -> HeaderValues<'a, 'n> ⓘ
The values of every field named name, in arrival order. Each
Set-Cookie is its own field (they are never comma-joined), so
this is how a client reads all of them.
§Examples
let cookies: Vec<&[u8]> = resp.header_all("set-cookie").collect();
assert_eq!(cookies, [&b"a=1"[..], &b"b=2; Path=/"[..]]);Sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Sourcepub fn header_list<'n>(&self, name: &'n str) -> ListElements<'a, 'n> ⓘ
pub fn header_list<'n>(&self, name: &'n str) -> ListElements<'a, 'n> ⓘ
The elements of a list field across every line with this name (see
RequestHead::header_list).
§Examples
assert_eq!(resp.header_list("vary").count(), 3);Sourcepub fn is_informational(&self) -> bool
pub fn is_informational(&self) -> bool
Whether this is an interim (1xx) response head, as reported by
ClientEvent::Informational.
§Examples
assert!(!resp.is_informational());Sourcepub fn framing(&self) -> BodyFraming
pub fn framing(&self) -> BodyFraming
How the response body is delimited (accounts for HEAD requests and
bodiless status codes).
§Examples
assert_eq!(resp.framing(), BodyFraming::UntilClose);Sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Whether the connection can carry another request after this response.
§Examples
assert!(resp.keep_alive());