Skip to content

Commit 5e8238c

Browse files
authored
docs(body): warn about no length check in aggregate (#2415)
The to_bytes and aggregate don't check how long the body is, so the user better be aware. Relates to #2414.
1 parent 43412a9 commit 5e8238c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/body/aggregate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ use crate::common::buf::BufList;
77
///
88
/// The returned `impl Buf` groups the `Buf`s from the `HttpBody` without
99
/// 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.
1016
pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
1117
where
1218
T: HttpBody,

src/body/to_bytes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ use super::HttpBody;
77
/// This may require copying the data into a single buffer. If you don't need
88
/// a contiguous buffer, prefer the [`aggregate`](crate::body::aggregate())
99
/// function.
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.
1016
pub async fn to_bytes<T>(body: T) -> Result<Bytes, T::Error>
1117
where
1218
T: HttpBody,

0 commit comments

Comments
 (0)