Skip to content

Body Limit

Body Limit middleware sets the maximum allowed size for a request body. If the size exceeds the configured limit, it sends a 413 Request Entity Too Large response.

The limit is enforced against both the Content-Length request header and the actual content read, which makes it resilient against spoofed headers. The limit is specified in bytes.

All core middleware lives in the middleware package:

import "github.com/labstack/echo/v5/middleware"
e := echo.New()
e.Use(middleware.BodyLimit(2_097_152)) // 2 MB
e := echo.New()
e.Use(middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{}))
type BodyLimitConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper
// LimitBytes is the maximum allowed size in bytes for a request body.
LimitBytes int64
}
// Effective defaults applied when fields are left unset (Limit is required).
BodyLimitConfig{
Skipper: DefaultSkipper,
}