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 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, Error>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Read some bytes from the body, returns how many bytes where read.
sourcepub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
pub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
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<(), Error>
pub async fn consume(&mut self) -> Result<(), Error>
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>,
) -> Response
pub fn new_message( status: impl Into<StatusCode>, msg: impl Into<String>, ) -> Response
Create a response with the given status and text body message.
sourcepub fn into_parts(self) -> (Parts, Body)
pub fn into_parts(self) -> (Parts, Body)
Consumes the response returning the head and body parts.
sourcepub fn from_parts(parts: Parts, body: Body) -> Response
pub fn from_parts(parts: Parts, body: Body) -> Response
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for 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