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
impl Response
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the final status code after redirects.
Sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns response headers mutably.
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns response extensions.
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns response extensions mutably.
Sourcepub const fn content_length(&self) -> Option<u64>
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.
Sourcepub const fn remote_addr(&self) -> Option<SocketAddr>
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.
Sourcepub const fn info(&self) -> ResponseInfo
pub const fn info(&self) -> ResponseInfo
Returns attempt, redirect, and response-header timing metadata.
Sourcepub fn error_for_status(self) -> Result<Self>
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.
Sourcepub fn error_for_status_ref(&self) -> Result<&Self>
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.
Sourcepub fn stream(self) -> ResponseStream
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.
Sourcepub async fn chunk(&mut self) -> Result<Option<Bytes>>
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.
Sourcepub fn upgrade(self) -> Upgrade ⓘ
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.
Sourcepub async fn bytes(self) -> Result<Bytes>
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.
Sourcepub async fn bytes_with_limit(self, limit: usize) -> Result<Bytes>
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.
Sourcepub async fn text(self) -> Result<String>
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.
Sourcepub async fn text_with_limit(self, limit: usize) -> Result<String>
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.
Sourcepub async fn json<T>(self) -> Result<T>where
T: DeserializeOwned,
pub async fn json<T>(self) -> Result<T>where
T: DeserializeOwned,
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.
Sourcepub async fn json_with_limit<T>(self, limit: usize) -> Result<T>where
T: DeserializeOwned,
pub async fn json_with_limit<T>(self, limit: usize) -> Result<T>where
T: DeserializeOwned,
Collects and decodes JSON up to an explicit byte limit.
Sourcepub async fn form<T>(self) -> Result<T>where
T: DeserializeOwned,
pub async fn form<T>(self) -> Result<T>where
T: DeserializeOwned,
Collects and decodes a URL-encoded form response.
Sourcepub async fn form_with_limit<T>(self, limit: usize) -> Result<T>where
T: DeserializeOwned,
pub async fn form_with_limit<T>(self, limit: usize) -> Result<T>where
T: DeserializeOwned,
Collects and decodes a URL-encoded form up to an explicit byte limit.