Body Size Limits
Protect your server from oversized request bodies.
Body Size Limits
Bklar supports a framework-level maxBodySize option to reject oversized request bodies early, returning 413 Payload Too Large.
Configuration
Set maxBodySize (in bytes) when creating your app:
const app = Bklar({
maxBodySize: 1024 * 1024, // 1MB
});How It Works
Two layers of protection:
-
Content-Length check — If the
Content-Lengthheader exceedsmaxBodySize, the request is rejected immediately with413, before any body is read. -
Streaming body check — When a body schema triggers
parseBody(), the framework reads the stream in chunks, tracking total bytes. If the limit is exceeded mid-stream, the reader is canceled and413is returned.
Error Response
{
"error": "Payload Too Large",
"message": "Request body exceeds size limit",
"statusCode": 413
}Without validation schemas
The streaming check runs only when body parsing is triggered (via validation
schemas). Always use the Content-Length header for the eager check.