Skip to main content

body_bytes

Function body_bytes 

Source
pub async fn body_bytes(req: Request<Incoming>) -> Result<Bytes, ServeError>
Expand description

Read the whole request body, refusing anything past the configured limit.

Returns 413 if the body exceeds MaxBodySize, checked from Content-Length before a byte is read and again while streaming, so a chunked body with no declared length cannot overrun by lying.

This is where the size limit lives, and it deliberately does not know about JSON. It used to be reachable only through json_body, which meant the crate’s body-size guarantee was a side effect of its JSON deserializer — an application reading bodies any other way got no limit at all, and the guarantee would have disappeared entirely had JSON ever become optional.