Skip to content

Commit

Permalink
Check before unmarshaling body
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswiagarwal committed Nov 14, 2019
1 parent 6f8c029 commit 2907f0f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions runtime/server_http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,16 +748,17 @@ func (req *ServerHTTPRequest) ReadAll() ([]byte, bool) {
func (req *ServerHTTPRequest) UnmarshalBody(
body json.Unmarshaler, rawBody []byte,
) bool {
err := body.UnmarshalJSON(rawBody)
if err != nil {
req.logger.Warn("Could not parse json", zap.Error(err))
if !req.parseFailed {
req.res.SendError(400, "Could not parse json: "+err.Error(), err)
req.parseFailed = true
if len(rawBody) > 0 {
err := body.UnmarshalJSON(rawBody)
if err != nil {
req.logger.Warn("Could not parse json", zap.Error(err))
if !req.parseFailed {
req.res.SendError(400, "Could not parse json: "+err.Error(), err)
req.parseFailed = true
}
return false
}
return false
}

return true
}

Expand Down

0 comments on commit 2907f0f

Please sign in to comment.