pub struct Response { /* private fields */ }Expand description
A high-level response wrapper providing transparent decompression and body management.
Response unifies both HTTP/2 and HTTP/3 connection payloads under a single,
public-API-compatible interface, implementing transparent decompression on hot paths.
§Key Architecture:
- Encapsulation: Keeps the underlying transport polymorphic (H2 vs H3) transparent to the client caller.
- Zero-Copy Decompression: Employs stack-allocated decompressors (
brotli_decompressor,zstd,flate2) uponbytes()invocation, decoding raw buffers directly into final owned storage.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(
status: StatusCode,
headers: HeaderMap,
body: ResponseBody,
url: String,
) -> Self
pub fn new( status: StatusCode, headers: HeaderMap, body: ResponseBody, url: String, ) -> Self
Creates a new Response from polymorphic parts.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the HTTP status code.
Sourcepub async fn bytes(self) -> Result<Bytes>
pub async fn bytes(self) -> Result<Bytes>
Collects the response body and returns the decompressed bytes.
This method is async as it must support asynchronous polling of H2 chunks.
Supports gzip, br, and zstd encodings.
§Implementation Strategy:
- Polymorphic Assembly: Accumulates body frames from TCP/H2 streaming loops, or yields the pre-buffered UDP/H3 vector.
- Transport Content-Encoding Negotiation: Inspects the
Content-Encodingheader and routes bytes dynamically through the appropriate decompression block (Brotli, Zstd, or Gzip).
Sourcepub async fn json<T: DeserializeOwned>(self) -> Result<T>
pub async fn json<T: DeserializeOwned>(self) -> Result<T>
Collects the body and decodes it as JSON.
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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