diff --git a/context/input.go b/context/input.go index 7e9f50b6..482b431a 100644 --- a/context/input.go +++ b/context/input.go @@ -17,6 +17,7 @@ package context import ( "bytes" "errors" + "io" "io/ioutil" "net/url" "reflect" @@ -313,8 +314,9 @@ func (input *BeegoInput) Session(key interface{}) interface{} { } // CopyBody returns the raw request body data as bytes. -func (input *BeegoInput) CopyBody() []byte { - requestbody, _ := ioutil.ReadAll(input.Context.Request.Body) +func (input *BeegoInput) CopyBody(MaxMemory int64) []byte { + safe := &io.LimitedReader{R:input.Context.Request.Body, N:MaxMemory} + requestbody, _ := ioutil.ReadAll(safe) input.Context.Request.Body.Close() bf := bytes.NewBuffer(requestbody) input.Context.Request.Body = ioutil.NopCloser(bf) diff --git a/router.go b/router.go index 53469b21..8d724ac6 100644 --- a/router.go +++ b/router.go @@ -653,7 +653,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) if r.Method != "GET" && r.Method != "HEAD" { if BConfig.CopyRequestBody && !context.Input.IsUpload() { - context.Input.CopyBody() + context.Input.CopyBody(BConfig.MaxMemory) } context.Input.ParseFormOrMulitForm(BConfig.MaxMemory) }