pub struct Response { /* private fields */ }Expand description
HTTP response with explicit decompression and a poll-based Body.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(
status: u16,
headers: Headers,
body: Bytes,
http_version: String,
) -> Self
pub fn new( status: u16, headers: Headers, body: Bytes, http_version: String, ) -> Self
Construct a buffered response. Used by the non-streaming transport paths and by tests/cache code that already have the full body in memory.
Sourcepub fn with_body(
status: u16,
headers: Headers,
body: Body,
http_version: String,
) -> Self
pub fn with_body( status: u16, headers: Headers, body: Body, http_version: String, ) -> Self
Construct a response that wraps an explicit Body. Used by the
streaming transport paths to publish the poll-based body to callers.
Sourcepub fn with_url(self, url: Url) -> Self
pub fn with_url(self, url: Url) -> Self
Set the effective URL (the URL that was actually requested).
pub fn http_version(&self) -> &str
pub fn status(&self) -> StatusCode
pub fn status_code(&self) -> u16
pub fn headers(&self) -> &Headers
Sourcepub async fn trailers(&mut self) -> Result<Option<Headers>>
pub async fn trailers(&mut self) -> Result<Option<Headers>>
Await the HTTP/2 response trailers for this response, if any.
gRPC carries grpc-status/grpc-message in a trailing HEADERS frame;
this surfaces them. Three outcomes:
Ok(Some(headers))- a real trailers frame arrived.Ok(None)- a clean trailer-less end, trailers were not requested (te: trailersabsent), or the response is buffered / non-H2.Err(_)- the stream was reset (RST_STREAM / transport error) before a clean end; distinct fromOk(None).
Await this only after the body stream has returned end: a resolved trailer channel does not imply the body has been fully drained.
pub fn url(&self) -> Option<&Url>
Sourcepub fn body_mut(&mut self) -> &mut Body
pub fn body_mut(&mut self) -> &mut Body
Mutable reference to the public poll-based body, used to drive
Body::frame without consuming the response.
Sourcepub fn into_body(self) -> Body
pub fn into_body(self) -> Body
Consume the response and return the body for poll-based draining.
Sourcepub fn buffered_bytes(&self) -> Option<&Bytes>
pub fn buffered_bytes(&self) -> Option<&Bytes>
Borrow the buffered body bytes, when the body is fully materialized.
Returns None for streaming bodies; use Body::frame or
Body::collect_to_bytes in that case.
pub fn bytes_raw(&self) -> Result<Bytes>
pub fn bytes(&self) -> Result<Bytes>
pub fn is_success(&self) -> bool
pub fn is_redirect(&self) -> bool
pub fn redirect_url(&self) -> Option<&str>
pub fn get_header(&self, name: &str) -> Option<&str>
pub fn get_headers(&self, name: &str) -> Vec<&str>
pub fn content_type(&self) -> Option<&str>
pub fn content_encoding(&self) -> Option<&str>
Sourcepub fn decoded_body(&self) -> Result<Bytes>
pub fn decoded_body(&self) -> Result<Bytes>
Decode body based on Content-Encoding (gzip, deflate, br, zstd).
Supports chained encodings (e.g., “gzip, deflate”) by applying decodings in reverse order.
Returns an error for streaming bodies; the caller must consume the
streaming body via Body::frame before applying decompression.