pub struct HttpResponse {
pub status: StatusCode,
pub reason: Option<String>,
pub headers: HeaderMap<HeaderValue>,
}Expand description
Parsed HTTP response with status line and headers.
Contains the status-line and header section of an HTTP response (RFC 9110 §6). The message body is handled separately via streaming.
Fields§
§status: StatusCodeHTTP status code (e.g., 200, 404, 502).
reason: Option<String>Reason phrase from the status line, if present.
headers: HeaderMap<HeaderValue>Header fields from the response.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn reason(&self) -> &str
pub fn reason(&self) -> &str
Returns the reason phrase, falling back to the canonical phrase for the status code.
Sourcepub fn status_line(&self) -> String
pub fn status_line(&self) -> String
Formats an HTTP/1.1 status line (e.g., HTTP/1.1 200 OK\r\n).
Sourcepub fn parse(buf: &[u8]) -> Result<Option<Self>>
pub fn parse(buf: &[u8]) -> Result<Option<Self>>
Parses a response from a buffer and returns None when incomplete.
Sourcepub fn parse_with_len(buf: &[u8]) -> Result<Option<(usize, Self)>>
pub fn parse_with_len(buf: &[u8]) -> Result<Option<(usize, Self)>>
Parses a response from a buffer and returns None when incomplete.
Returns the length of the header section and the response.
Sourcepub async fn peek(reader: &mut impl Prebufferable) -> Result<(usize, Self)>
pub async fn peek(reader: &mut impl Prebufferable) -> Result<(usize, Self)>
Reads and parses the response status line and header section.
Does not remove the header section from reader.
Returns io::ErrorKind::OutOfMemory if the header section exceeds the buffer limit.