pub struct Response { /* private fields */ }Expand description
A response whose head has arrived and whose body is still on the wire.
bytes and text collect the body (and
trailers, if any) under the remainder of the request deadline, so “request
timeout” covers head and body.
The deadline is absolute, fixed when the request started, and it keeps
running while this value is held. Time spent between receiving the head and
collecting the body comes out of the same budget, so a response parked while
the caller does other work can fail with
Error::Timeout { phase: Body } even though
its bytes have already arrived. Collect promptly, or give such requests a
longer request_timeout.
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
The response status code.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the status code is in the 2xx range.
Sourcepub async fn bytes(
self,
max_size: Option<usize>,
) -> Result<(Bytes, Option<HeaderMap>), Error>
pub async fn bytes( self, max_size: Option<usize>, ) -> Result<(Bytes, Option<HeaderMap>), Error>
Collects the response body, returning it together with the trailers (HTTP/3 trailing header section), if the server sent any.
max_size bounds how much is buffered; a larger body fails with
Error::BodyTooLarge. None means unbounded — prefer a limit
whenever the server is not fully trusted. Collection runs under the
remainder of the request deadline.
Sourcepub async fn text(
self,
max_size: Option<usize>,
) -> Result<(String, Option<HeaderMap>), Error>
pub async fn text( self, max_size: Option<usize>, ) -> Result<(String, Option<HeaderMap>), Error>
Collects the response body as a UTF-8 string, returning it together with the trailers, if the server sent any.
Same limits and deadline as bytes; a body that is not
valid UTF-8 fails with Error::InvalidBody.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Response
impl !UnwindSafe for Response
impl Freeze for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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