Skip to main content

Response

Struct Response 

Source
pub struct Response { /* private fields */ }
Expand description

A final response with streaming body access and bounded consumers. A final response with streaming body access and bounded consumers. A final response with streaming body access and bounded consumers. A final HTTP response with a one-shot streaming Tez body.

An HTTP status is never an error by itself. Inspect Response::status to decide what success means for the operation. Borrow the one-shot body to stream frames, consume it with a collecting helper, or call Response::discard.

Implementations§

Source§

impl Response

Source

pub fn status(&self) -> StatusCode

Returns the final status code after redirects.

Source

pub fn version(&self) -> Version

Returns the HTTP version used by the final response.

Source

pub fn headers(&self) -> &HeaderMap

Returns response headers, preserving repeated values.

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Returns response headers mutably.

Source

pub fn extensions(&self) -> &Extensions

Returns response extensions.

Source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns response extensions mutably.

Source

pub fn url(&self) -> &Uri

Returns the final absolute URL after redirects.

Source

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

Returns the exposed response body length when it is known.

This is body metadata after the client’s decompression policy, not a parsed Content-Length header. Automatically decompressed or streaming responses commonly have no known length.

Source

pub const fn remote_addr(&self) -> Option<SocketAddr>

Returns the final transport peer address when it is known.

When a proxy is in use, this may be the proxy address rather than the origin server address.

Source

pub const fn info(&self) -> ResponseInfo

Returns attempt, redirect, and response-header timing metadata.

Source

pub fn error_for_status(self) -> Result<Self>

Converts a client or server response status into an error.

Informational, successful, and redirect responses are returned unchanged.

§Errors

Returns a status error for 4xx and 5xx responses.

Source

pub fn error_for_status_ref(&self) -> Result<&Self>

Checks whether the response has a client or server error status.

§Errors

Returns a status error for 4xx and 5xx responses.

Source

pub fn body(&self) -> &Body

Returns the one-shot streaming response body.

Source

pub fn body_mut(&mut self) -> &mut Body

Returns the one-shot streaming response body mutably.

Source

pub fn into_body(self) -> Body

Consumes the response and returns its one-shot streaming body.

Source

pub fn stream(self) -> ResponseStream

Consumes the response as an incremental body stream.

Select JSON, NDJSON, or SSE framing explicitly on the returned stream, or consume it as a raw http_body::Body.

Source

pub async fn chunk(&mut self) -> Result<Option<Bytes>>

Reads the next response-body data chunk.

Empty data frames and trailers are skipped. None means the complete body has been consumed and the connection is eligible for reuse.

Source

pub fn upgrade(self) -> Upgrade ⓘ

Completes an HTTP protocol switch negotiated by this response.

Validate the status and protocol-specific response headers before awaiting the returned future. The response body is discarded and its HTTP/1 connection is permanently removed from the pool.

Source

pub async fn bytes(self) -> Result<Bytes>

Collects response body data up to the client’s configured limit.

The limit applies after automatic decompression when enabled. This consumes the response. Use streaming access for larger bodies.

§Errors

Returns an error if reading fails or the decoded body exceeds the limit.

Source

pub async fn bytes_with_limit(self, limit: usize) -> Result<Bytes>

Collects response body data up to an explicit limit.

This overrides the client collection limit for this response without changing streaming behavior.

Source

pub async fn text(self) -> Result<String>

Collects the response body as text.

The limit applies after automatic decompression when enabled. The character encoding comes from Content-Type and defaults to UTF-8. Malformed input is rejected rather than replaced.

§Errors

Returns an error if collection or character decoding fails.

Source

pub async fn text_with_limit(self, limit: usize) -> Result<String>

Collects the response body as text up to an explicit byte limit.

§Errors

Returns an error if collection or character decoding fails.

Source

pub async fn json<T>(self) -> Result<T>

Collects the response body as JSON.

The limit applies after automatic decompression when enabled. This consumes the response. JSON is decoded regardless of the response Content-Type value.

§Errors

Returns an error if collection fails or the body is not valid JSON for T.

Source

pub async fn json_with_limit<T>(self, limit: usize) -> Result<T>

Collects and decodes JSON up to an explicit byte limit.

Source

pub async fn form<T>(self) -> Result<T>

Collects and decodes a URL-encoded form response.

Source

pub async fn form_with_limit<T>(self, limit: usize) -> Result<T>

Collects and decodes a URL-encoded form up to an explicit byte limit.

Source

pub async fn copy_to<W>(self, writer: &mut W) -> Result<u64>
where W: AsyncWrite + Unpin + ?Sized,

Copies the decoded response body into an asynchronous writer.

This path retains at most one response chunk and observes connection backpressure. It returns the number of bytes written.

Source

pub async fn discard(self) -> Result<()>

Drains the body without retaining it, allowing connection reuse.

This consumes the response and observes the client’s total deadline.

§Errors

Returns an error if the body cannot be read to completion.

Trait Implementations§

Source§

impl Debug for Response

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more