1 use bytes::Buf;
2 
3 use super::HttpBody;
4 use crate::common::buf::BufList;
5 
6 /// 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))]
aggregate<T>(body: T) -> Result<impl Buf, T::Error> where T: HttpBody,23 pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
24 where
25     T: HttpBody,
26 {
27     let mut bufs = BufList::new();
28 
29     futures_util::pin_mut!(body);
30     while let Some(buf) = body.data().await {
31         let buf = buf?;
32         if buf.has_remaining() {
33             bufs.push(buf);
34         }
35     }
36 
37     Ok(bufs)
38 }
39