ClientResponse

Trait ClientResponse 

Source
pub trait ClientResponse:
    Send
    + Sync
    + Sized {
    type ResponseError: DecodeError + Send;
    type StreamError: Error + Send + Sync;
    type Headers: ResponseHeaders;

    // Required methods
    fn content_length(&self) -> Option<u64>;
    fn content_type(&self) -> Option<&str>;
    fn headers(&self) -> Self::Headers;
    fn into_result(self) -> Result<Self, Self::ResponseError>;
    fn stream(
        self,
    ) -> Box<dyn Stream<Item = Result<Bytes, Self::StreamError>> + Unpin + Send + Sync>;
}
Available on crate feature http only.
Expand description

A wrapper trait for an HTTP response that exposes only functionality necessary for retrieving the stream content. If the reqwest feature is enabled, this trait is implemented for reqwest::Response. This can be implemented for a custom HTTP response if desired.

Required Associated Types§

Source

type ResponseError: DecodeError + Send

Error type returned by the underlying response.

Source

type StreamError: Error + Send + Sync

Error type returned by the stream.

Source

type Headers: ResponseHeaders

Object containing HTTP response headers.

Required Methods§

Source

fn content_length(&self) -> Option<u64>

The size of the remote resource in bytes. The result should be None if the stream is infinite or doesn’t have a known length.

Source

fn content_type(&self) -> Option<&str>

The content-type response header. This should be in the standard format of <type>/<subtype>.

Source

fn headers(&self) -> Self::Headers

Object containing HTTP response headers.

Source

fn into_result(self) -> Result<Self, Self::ResponseError>

Turns the response into an error if the response was not successful.

Source

fn stream( self, ) -> Box<dyn Stream<Item = Result<Bytes, Self::StreamError>> + Unpin + Send + Sync>

Converts the response into a byte stream

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ClientResponse for Response

Available on crate feature reqwest only.

Implementors§