histoire
Version:
A fast story book powered by Vite
36 lines • 1.65 kB
TypeScript
import type { IncomingMessage, ServerResponse } from 'node:http';
import { Buffer } from 'node:buffer';
/** Default JSON body cap shared by UI HTTP routes. */
export declare const JSON_BODY_BYTES: number;
/** Thrown when a request body exceeds its route limit; routes map it to their own message. */
export declare class RequestBodyTooLargeError extends Error {
constructor();
}
/**
* Rejects cross-origin browser writes (credentials, uploads) before reading the body:
* POST only, exact content type, and an `Origin` matching the request host and protocol.
* @param request Incoming request.
* @param contentType Required media type, ignoring parameters.
*/
export declare function isSameOriginPost(request: IncomingMessage, contentType?: string): boolean;
/**
* Reads a whole request body, stopping as soon as it exceeds `limit` bytes.
* @param request Incoming request.
* @param limit Largest accepted body in bytes.
* @throws {RequestBodyTooLargeError} When the body is larger than `limit`.
*/
export declare function readBody(request: IncomingMessage, limit: number): Promise<Buffer>;
/**
* Reads and parses a bounded JSON body without logging private payloads.
* @param request Incoming request.
* @param limit Largest accepted body in bytes.
*/
export declare function readJsonBody(request: IncomingMessage, limit?: number): Promise<unknown>;
/**
* Writes one JSON response.
* @param response Outgoing response.
* @param status HTTP status.
* @param value JSON-serializable body.
*/
export declare function sendJson(response: ServerResponse, status: number, value: unknown): void;
//# sourceMappingURL=http-body.d.ts.map