mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-21 16:58:08 +08:00
handle Body return EOF
handle Body will return EOF when it used in middleware.
This commit is contained in:
parent
e5261480fd
commit
f640a4972c
@ -28,6 +28,13 @@ func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
if req == nil || req.Body == nil {
|
||||
return fmt.Errorf("invalid request")
|
||||
}
|
||||
// read the body to a variable
|
||||
bodyBytes, _ := ioutil.ReadAll(req.Body)
|
||||
req.Body.Close()
|
||||
tempBody := ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
|
||||
//reset the body to the original unread state
|
||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
return decodeJSON(req.Body, obj)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user