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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin for HttpResponse
impl UnwindSafe for HttpResponse
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more