mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 20:22:20 +08:00
handle Body return EOF
handle Body will return EOF when it used in middleware.
This commit is contained in:
parent
e5261480fd
commit
af0276fe98
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user