1use bytes::Buf;
23use super::HttpBody;
4use crate::common::buf::BufList;
56/// Aggregate the data buffers from a body asynchronously.
7///
8/// The returned `impl Buf` groups the `Buf`s from the `HttpBody` without
9/// copying them. This is ideal if you don't require a contiguous buffer.
10///
11/// # Note
12///
13/// Care needs to be taken if the remote is untrusted. The function doesn't implement any length
14/// checks and an malicious peer might make it consume arbitrary amounts of memory. Checking the
15/// `Content-Length` is a possibility, but it is not strictly mandated to be present.
16#[cfg_attr(
17 feature = "deprecated",
18 deprecated(
19 note = "This function has been replaced by a method on the `hyper::body::HttpBody` trait. Use `.collect().await?.aggregate()` instead."
20)
21)]
22#[cfg_attr(feature = "deprecated", allow(deprecated))]
23pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
24where
25T: HttpBody,
26{
27let mut bufs = BufList::new();
2829futures_util::pin_mut!(body);
30while let Some(buf) = body.data().await {
31let buf = buf?;
32if buf.has_remaining() {
33 bufs.push(buf);
34 }
35 }
3637Ok(bufs)
38}