Skip to main content

Module body_limit

Module body_limit 

Source
Expand description

A per-route ceiling on the request body.

The server has a limit of its own (crate::Limits) that protects the process: a body over it is refused before it is buffered. That limit has to be as large as the biggest upload the application accepts anywhere, which makes it useless as policy — a JSON endpoint that expects a kilobyte should not accept the fifty megabytes the avatar upload needs. This middleware is the policy: tighter, and per group.

r.group("/api", |api| {
    api.middleware(BodyLimit::kilobytes(64));
    …
});

By the time middleware runs the body has been read, so this does not save memory — the server’s limit does that. It saves the handler from parsing something it was never meant to receive, and tells the client why.

Structs§

BodyLimit