pub struct Response(/* private fields */);
Expand description
HTTP response.
Implementations§
source§impl Response
impl Response
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the StatusCode
.
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns a reference to the associated header field map.
sourcepub fn content_len(&self) -> Option<ByteLength>
pub fn content_len(&self) -> Option<ByteLength>
Decode content-length value if it is present in the headers.
Get the configured cookie jar used for persisting cookies from this response, if any.
Only returns None
if the default_client
was replaced by one with cookies disabled.
sourcepub fn effective_uri(&self) -> Option<&Uri>
pub fn effective_uri(&self) -> Option<&Uri>
Get the effective URI of this response. This value differs from the original URI provided when making the request if at least one redirect was followed.
sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read some bytes from the body, returns how many bytes where read.
sourcepub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
pub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the from the body to exactly fill the buffer.
sourcepub async fn json<O>(&mut self) -> Result<O, Error>where
O: DeserializeOwned + Unpin,
pub async fn json<O>(&mut self) -> Result<O, Error>where
O: DeserializeOwned + Unpin,
Deserialize the response body as JSON.
sourcepub fn metrics(&self) -> Metrics
pub fn metrics(&self) -> Metrics
Metrics for the task transfer.
Metrics are enabled in the default_client
and can be toggled for each request using the
RequestBuilder::metrics
method. If disabled returns Metrics::zero
.
sourcepub async fn consume(&mut self) -> Result<()>
pub async fn consume(&mut self) -> Result<()>
Drop the request without dropping the connection.
This receives and discards any remaining bytes in the response stream. When a response is dropped without finishing the connection is discarded so it cannot be reused for connections older then HTTP/2.
You should call this method before dropping if you expect the remaining bytes to be consumed quickly and don’t known that HTTP/2 or newer is being used.
sourcepub fn new_message(
status: impl Into<StatusCode>,
msg: impl Into<String>,
) -> Self
pub fn new_message( status: impl Into<StatusCode>, msg: impl Into<String>, ) -> Self
Create a response with the given status and text body message.
sourcepub fn new(
status: StatusCode,
headers: HeaderMap<HeaderValue>,
body: Body,
) -> Self
pub fn new( status: StatusCode, headers: HeaderMap<HeaderValue>, body: Body, ) -> Self
New response.
sourcepub fn into_parts(self) -> (ResponseParts, Body)
pub fn into_parts(self) -> (ResponseParts, Body)
Consumes the response returning the head and body parts.
sourcepub fn from_parts(parts: ResponseParts, body: Body) -> Self
pub fn from_parts(parts: ResponseParts, body: Body) -> Self
New response from given head and body.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl !RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl !UnwindSafe 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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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