Skip to main content

read_bounded

Function read_bounded 

Source
pub async fn read_bounded(
    response: Response,
    max_bytes: u64,
) -> Result<String, ReadError>
Expand description

Read a response body, refusing one larger than max_bytes.

A declared Content-Length past the ceiling is refused before a byte is read, but that is a shortcut rather than the guarantee: reqwest strips the header from a response it decompresses, and chunked transfer encoding never sends one. The per-chunk cap is what actually holds, and it counts decoded bytes - which is both what gets allocated and what makes a body that inflates without limit refusable.

The timeout on the client is not a size bound. A fast host can send a great deal inside one, and the body is buffered whole.