[]previous and next page

readTextLimited

Reads a request body as text, never more than maxBytes (a smaller limit than the handler's, for endpoints that accept less).

Reads a request body as text, never more than maxBytes (a smaller limit than the handler's, for endpoints that accept less).

Import#

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

Signature#

ts
function readTextLimited(request: Request, maxBytes: number): Promise<string>

Parameters#

Name Description
request The request.
maxBytes The limit in bytes (Infinity for none, on purpose).

Returns#

The text.

Throws#

  • BodyTooLargeError when the body is larger, before reading anything when Content-Length says so.
  • RangeError when maxBytes is NaN or negative.
  • HttpError 415 when the charset parameter is not one of utf-8, utf-16le, utf-16be, iso-8859-1, latin1; 400 when the bytes are not valid text in the body's charset (the text is never repaired with U+FFFD).

Examples#

ts
const text = await readTextLimited(request, 4096);