Middleware
Body Limit
Reject oversized request bodies before handlers consume them.
BodyLimit rejects request bodies over a size you choose with 413 Request Entity Too Large, before handlers read them. Use it to set a tighter limit on particular routes than the app-wide Config.BodyLimit, which binding already enforces.
Quick start
Section titled “Quick start”app.Use(middleware.BodyLimit(10 * middleware.MB))Config
Section titled “Config”app.Use(middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{ Limit: 10 * middleware.MB,}))Fields
Section titled “Fields”| Field | Meaning |
|---|---|
Skipper |
Skip the limit for selected requests |
Limit |
Required maximum size in bytes |
Size helpers
Section titled “Size helpers”Zinc exposes convenient constants:
middleware.Bmiddleware.KBmiddleware.MBmiddleware.GB
Failure behavior
Section titled “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.