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).
§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 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());Trait Implementations§
Source§impl<'a> Clone for ResponseHead<'a>
impl<'a> Clone for ResponseHead<'a>
impl<'a> Copy for ResponseHead<'a>
Auto Trait Implementations§
impl<'a> Freeze for ResponseHead<'a>
impl<'a> RefUnwindSafe for ResponseHead<'a>
impl<'a> Send for ResponseHead<'a>
impl<'a> Sync for ResponseHead<'a>
impl<'a> Unpin for ResponseHead<'a>
impl<'a> UnsafeUnpin for ResponseHead<'a>
impl<'a> UnwindSafe for ResponseHead<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more