Function awc::body::to_bytes_limited
pub async fn to_bytes_limited<B>(
body: B,
limit: usize
) -> Result<Result<Bytes, <B as MessageBody>::Error>, BodyLimitExceeded>where
B: MessageBody,
Expand description
Collects the bytes produced by body
, up to limit
bytes.
If a chunk read from poll_next
causes the total number of bytes read to exceed limit
, an
Err(BodyLimitExceeded)
is returned.
Any errors produced by the body stream are returned immediately as Ok(Err(B::Error))
.
ยงExamples
use actix_http::body::{self, to_bytes_limited};
use bytes::Bytes;
let body = body::None::new();
let bytes = to_bytes_limited(body, 10).await.unwrap().unwrap();
assert!(bytes.is_empty());
let body = Bytes::from_static(b"123");
let bytes = to_bytes_limited(body, 10).await.unwrap().unwrap();
assert_eq!(bytes, "123");
let body = Bytes::from_static(b"123");
assert!(to_bytes_limited(body, 2).await.is_err());