pub trait ResponseExt {
// Required methods
fn collect_bytes(self) -> impl Future<Output = Result<Bytes, Error>> + Send;
fn collect_bytes_limited(
self,
max: usize,
) -> impl Future<Output = Result<Bytes, Error>> + Send;
fn into_read(self) -> impl AsyncRead + Send + Unpin + 'static;
}Expand description
Helper methods for http::Response.
Required Methods§
Sourcefn collect_bytes(self) -> impl Future<Output = Result<Bytes, Error>> + Send
fn collect_bytes(self) -> impl Future<Output = Result<Bytes, Error>> + Send
Collect the response body into a bytes::Bytes with no size limit.
Use this only when the body is locally generated or otherwise trusted to be small. For
any body read from a network peer (a control/DERP/upstream server response — all of which
this fork treats as hostile-capable), prefer
collect_bytes_limited: collect() here buffers the
entire body into memory before returning, so a malicious or MITM’d server answering a
short request with a multi-gigabyte streamed body would OOM the client (a length check
after collect_bytes is too late — the allocation already happened).
Sourcefn collect_bytes_limited(
self,
max: usize,
) -> impl Future<Output = Result<Bytes, Error>> + Send
fn collect_bytes_limited( self, max: usize, ) -> impl Future<Output = Result<Bytes, Error>> + Send
Collect the response body into a bytes::Bytes, failing if it exceeds max bytes.
The body is wrapped in http_body_util::Limited, which aborts collection as soon as
more than max bytes arrive — so the allocation is bounded during the read, mirroring
Go’s io.LimitedReader-bounded body reads. An over-limit body yields
Error::BodyTooLarge (distinct from a transient Error::Io, so callers can treat it
as terminal). This is the body reader every network-response caller should use; pick max
to comfortably fit the largest legitimate response for that endpoint.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".