elysia-body-limit
v1.1.0
Published
Add body size limits for Elysia!!
Maintainers
Readme
elysia-body-limit
A lightweight body size limit plugin for Elysia.js applications that helps secure your apps by limiting request body size.
Features
- 📏 Configurable maximum body size
- 🔍 Content-Length header validation
- 🔄 Transfer-Encoding stream monitoring
- ⚡ Bun maxRequestBodySize validation
- 🛡️ Strict Content-Length mode
- 🎯 Custom error handlers
Installation
bun add elysia-body-limitBasic Usage
import { Elysia } from "elysia";
import { bodyLimit } from "elysia-body-limit";
// Your current Elysia instance is now under protect!
const app = new Elysia()
.use(bodyLimit({
maxSize: "10m"
}))
.post("/", ({ body }) => "Body received!")
.listen(3000);[!NOTE] The middleware automatically validates that your
maxSizeis not larger than Bun'smaxRequestBodySizeconfiguration.
How It Works
- Content-Length Check: For requests with
Content-Lengthheader, the middleware validates the size before processing - Transfer-Encoding Support: When
bodyCheckis enabled, the middleware monitors streaming requests to enforce size limits - Bun Configuration Validation: Automatically warns if your limit exceeds Bun's internal
maxRequestBodySize
