diff --git a/context.go b/context.go index 5dc7f8a0f5..b1fa51e620 100644 --- a/context.go +++ b/context.go @@ -5,6 +5,7 @@ package gin import ( + "bytes" "errors" "fmt" "io" @@ -640,6 +641,10 @@ func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (e if err != nil { return err } + // close the body + c.Request.Body.Close() + // reset the body to the original unread state + c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) c.Set(BodyBytesKey, body) } return bb.BindBody(body, obj)