handle Body return EOF

handle Body will return EOF when it used in middleware.
This commit is contained in:
2019-03-13 13:16:03 +08:00 committed by GitHub
parent e5261480fd
commit af0276fe98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)