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{}))

BodyLimitConfig · github.com/labstack/echo/v5@5196b9b

Fields from package source
FieldTypeDescriptionSource
Skipper Skipper Skipper defines a function to skip middleware. L17
LimitBytes int64 LimitBytes is maximum allowed size in bytes for a request body L20
Functions from package source
TypeSource
func BodyLimit(limitBytes int64) echo.MiddlewareFunc L34
func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc L42
// Effective defaults applied when fields are left unset (Limit is required).
BodyLimitConfig{
Skipper: DefaultSkipper,
}