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-Lengthsays so. - RangeError when
maxBytesisNaNor negative. - HttpError 415 when the
charsetparameter is not one ofutf-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);