Skip to Content
Senri

Body limit

Set a route's body size limit with bodyLimit() (replaces the default 1 MiB)

import { ,  } from "@senrijs/senri";

const  = ();

.("/import", ({ : 50 * 1024 * 1024 }));   // up to 50 MiB on this route
  • Over the limit, the response is 413
  • It replaces the app's default limit (1 MiB). They do not stack, so it can be larger or smaller than the default
  • With Content-Length, the request is refused before reading. Without it (chunked transfer), the body is counted as it is read
  • It also applies to routes that read c.req.body as a stream
  • maxSize must be a finite number. For no limit at all, use createApp({ maxBodySize: Infinity })

The whole story of body limits is in Request bodies and limits.

Change the response

.("/import", ({ : 1024 * 1024, : () => ({ : "too large" }) }));

The status is set to 413 before onError is called, so a returned string or object is sent with 413. A returned Response keeps its own status.

Options

Prop

Type

On this page