Files
SnowLuma/.pnpm-store/v11/files/84/b6e0df1ecf03b9ac56cdd7d5ea2a455e3408b5606f85bed25c54a210617ec2e6a4834b59932395a5507a32678f44e94bfbd329ca68579476387eea215cd5b7
T
TanTan 2a69b23b47
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
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

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 {};