Back to

Package limit

Latest Go to latest

The latest major version is .

Published: Aug 6, 2020 | License: MIT | Module:



var (
	// DefaultBodyLimitConfig is the default BodyLimit middleware config.
	DefaultBodyLimitConfig = BodyLimitConfig{
		Skipper: DefaultSkipper,

func BodyLimit

func BodyLimit(limit string) echo.MiddlewareFunc

BodyLimit returns a BodyLimit middleware.

BodyLimit middleware sets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends "413 - Request Entity Too Large" response. The BodyLimit is determined based on both `Content-Length` request header and actual content read, which makes it super secure. Limit can be specified as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.

func BodyLimitWithConfig

func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc

BodyLimitWithConfig returns a BodyLimit middleware with config. See: `BodyLimit()`.

func RequestSizeLimiter

func RequestSizeLimiter(limit int64) gin.HandlerFunc

RequestSizeLimiter returns a middleware that limits the size of request When a request is over the limit, the following will happen: * Error will be added to the context * Connection: close header will be set * Error 413 will be sent to the client (http.StatusRequestEntityTooLarge) * Current context will be aborted

type BodyLimitConfig

type BodyLimitConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper Skipper

	// Maximum allowed size for a request body, it can be specified
	// as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.
	Limit string `yaml:"limit"`
	// contains filtered or unexported fields

BodyLimitConfig defines the config for BodyLimit middleware.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier