mirror of
https://github.com/kataras/iris.git
synced 2026-01-01 09:17:02 +00:00
Update to 6.0.3: Add an easy way to set a request body size limit per client or globally for newcomers
This commit is contained in:
19
context.go
19
context.go
@@ -390,6 +390,25 @@ func (ctx *Context) FormFile(key string) (multipart.File, *multipart.FileHeader,
|
||||
// -------------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: No default max body size http package has some built'n protection for DoS attacks
|
||||
// See iris.Config.MaxBytesReader, https://github.com/golang/go/issues/2093#issuecomment-66057813
|
||||
// and https://github.com/golang/go/issues/2093#issuecomment-66057824
|
||||
|
||||
// LimitRequestBodySize is a middleware which sets a request body size limit for all next handlers
|
||||
// should be registered before all other handlers
|
||||
var LimitRequestBodySize = func(maxRequestBodySizeBytes int64) HandlerFunc {
|
||||
return func(ctx *Context) {
|
||||
ctx.SetMaxRequestBodySize(maxRequestBodySizeBytes)
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// SetMaxRequestBodySize sets a limit to the request body size
|
||||
// should be called before reading the request body from the client
|
||||
func (ctx *Context) SetMaxRequestBodySize(limitOverBytes int64) {
|
||||
ctx.Request.Body = http.MaxBytesReader(ctx.ResponseWriter, ctx.Request.Body, limitOverBytes)
|
||||
}
|
||||
|
||||
// BodyDecoder is an interface which any struct can implement in order to customize the decode action
|
||||
// from ReadJSON and ReadXML
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user