2016-10-20 11:30:53 -07:00
|
|
|
+++
|
2016-11-28 20:30:42 -08:00
|
|
|
title = "Body Limit Middleware"
|
2016-10-20 11:30:53 -07:00
|
|
|
description = "Body limit middleware for Echo"
|
2016-11-20 14:16:22 -08:00
|
|
|
[menu.main]
|
2016-11-28 20:30:42 -08:00
|
|
|
name = "Body Limit"
|
2016-10-20 11:30:53 -07:00
|
|
|
parent = "middleware"
|
|
|
|
weight = 5
|
|
|
|
+++
|
|
|
|
|
2016-11-28 20:30:42 -08:00
|
|
|
Body limit middleware sets the maximum allowed size for a request body, if the
|
2016-10-20 11:30:53 -07:00
|
|
|
size exceeds the configured limit, it sends "413 - Request Entity Too Large"
|
|
|
|
response. The body limit 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.
|
|
|
|
|
|
|
|
*Usage*
|
|
|
|
|
|
|
|
```go
|
|
|
|
e := echo.New()
|
|
|
|
e.Use(middleware.BodyLimit("2M"))
|
|
|
|
```
|
2016-11-19 22:13:05 -08:00
|
|
|
|
|
|
|
## Custom Configuration
|
2016-10-20 11:30:53 -07:00
|
|
|
|
|
|
|
*Usage*
|
|
|
|
|
|
|
|
```go
|
|
|
|
e := echo.New()
|
2016-12-18 20:11:25 +01:00
|
|
|
e.Use(middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{}))
|
2016-10-20 11:30:53 -07:00
|
|
|
```
|
|
|
|
|
2016-11-19 22:13:05 -08:00
|
|
|
## Configuration
|
2016-10-20 11:30:53 -07:00
|
|
|
|
|
|
|
```go
|
|
|
|
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 `json:"limit"`
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
*Default Configuration*
|
|
|
|
|
|
|
|
```go
|
|
|
|
DefaultBodyLimitConfig = BodyLimitConfig{
|
|
|
|
Skipper: defaultSkipper,
|
|
|
|
}
|
|
|
|
```
|