Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
import { MiddlewareHandler } from "../../types.js";
|
|
import { Context } from "../../context.js";
|
|
//#region src/middleware/body-limit/index.d.ts
|
|
type OnError = (c: Context) => Response | Promise<Response>;
|
|
type BodyLimitOptions = {
|
|
maxSize: number;
|
|
onError?: OnError;
|
|
};
|
|
/**
|
|
* Body Limit Middleware for Hono.
|
|
*
|
|
* @see {@link https://hono.dev/docs/middleware/builtin/body-limit}
|
|
*
|
|
* @param {BodyLimitOptions} options - The options for the body limit middleware.
|
|
* @param {number} options.maxSize - The maximum body size allowed.
|
|
* @param {OnError} [options.onError] - The error handler to be invoked if the specified body size is exceeded.
|
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const app = new Hono()
|
|
*
|
|
* app.post(
|
|
* '/upload',
|
|
* bodyLimit({
|
|
* maxSize: 50 * 1024, // 50kb
|
|
* onError: (c) => {
|
|
* return c.text('overflow :(', 413)
|
|
* },
|
|
* }),
|
|
* async (c) => {
|
|
* const body = await c.req.parseBody()
|
|
* if (body['file'] instanceof File) {
|
|
* console.log(`Got file sized: ${body['file'].size}`)
|
|
* }
|
|
* return c.text('pass :)')
|
|
* }
|
|
* )
|
|
* ```
|
|
*/
|
|
export declare const bodyLimit: (options: BodyLimitOptions) => MiddlewareHandler;
|
|
//#endregion
|
|
export {};
|