Skip to main content

Body Limit

Request body size limiter. Rejects requests with bodies larger than the configured limit before they reach your handler.

Usage

r.Use(middleware.BodyLimit("1M"))

How It Works

  • Wraps c.Request.Body with a http.MaxBytesReader
  • If the body exceeds the limit, the reader returns an error on read
  • The middleware returns 413 Request Entity Too Large

Supported Units

  • B - bytes
  • K - kilobytes
  • M - megabytes
  • G - gigabytes

Examples: "500B", "2K", "10M", "1G"