Body Limit
BodyLimit protects endpoints from unexpectedly large request bodies.
Quick start
app.Use(middleware.BodyLimit(10 * middleware.MB))
Config
app.Use(middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{
Limit: 10 * middleware.MB,
}))
Fields
| Field | Meaning |
|---|---|
Skipper | Skip the limit for selected requests |
Limit | Required maximum size in bytes |
Size helpers
Zinc exposes convenient constants:
middleware.Bmiddleware.KBmiddleware.MBmiddleware.GB
Failure behavior
When the body exceeds the configured limit, Zinc returns a *middleware.BodyLimitError.
That error includes:
LimitObservedSource
Source tells you whether the limit was exceeded from:
- the request's
Content-Length - actual body reads
The error unwraps to zinc.ErrRequestEntityTooLarge.