read_reqwest_body_limited

Function read_reqwest_body_limited 

Source
pub async fn read_reqwest_body_limited<E>(
    response: Response,
    context: &str,
    max_bytes: usize,
    map_error: impl Fn(String) -> E,
) -> Result<Vec<u8>, E>
Expand description

Reads a reqwest response body while enforcing a strict byte limit.

A declared Content-Length above max_bytes is rejected before streaming. The same limit is enforced while reading so missing or incorrect length headers cannot bypass it. map_error keeps this helper independent from each caller’s error boundary.

§Errors

Returns the caller-provided error when the declared or observed body exceeds max_bytes, when the response stream fails, or when the accumulated size would overflow usize.