[]previous and next page

limitBody

Returns a request whose body errors with BodyTooLargeError as soon as more than maxBodyBytes have been read.

Returns a request whose body errors with BodyTooLargeError as soon as more than maxBodyBytes have been read. This enforces the limit for chunked bodies and for clients that lie in Content-Length; the body is never buffered here.

Import#

ts
import { limitBody } from "@shadow-js/dusk/server";

Signature#

ts
function limitBody(request: Request, maxBodyBytes: number, signal: AbortSignal): Request

Parameters#

Name Description
request The original request.
maxBodyBytes The limit in bytes.
signal The signal the new request should carry.

Returns#

A request that behaves like request, with a bounded body.

Examples#

ts
const bounded = limitBody(request, 1024, new AbortController().signal);