mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:57:07 +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
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -640,6 +641,10 @@ func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
c.Set(BodyBytesKey, body)
|
||||||
}
|
}
|
||||||
return bb.BindBody(body, obj)
|
return bb.BindBody(body, obj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user