Added check to handle nil request body in nethttpadaptor (#218)
This commit is contained in:
parent
df6c3c3e32
commit
e67ea01fbe
|
@ -17,12 +17,14 @@ func NewNetHTTPHandlerFunc(h fasthttp.RequestHandler) http.HandlerFunc {
|
|||
remoteAddr := net.IPAddr{remoteIP, ""} //nolint
|
||||
c.Init(&fasthttp.Request{}, &remoteAddr, nil)
|
||||
|
||||
reqBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Errorf("error reading request body, %+v", err)
|
||||
return
|
||||
if r.Body != nil {
|
||||
reqBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Errorf("error reading request body, %+v", err)
|
||||
return
|
||||
}
|
||||
c.Request.SetBody(reqBody)
|
||||
}
|
||||
c.Request.SetBody(reqBody)
|
||||
c.Request.SetRequestURI(r.URL.RequestURI())
|
||||
c.Request.URI().SetScheme(r.URL.Scheme)
|
||||
c.Request.SetHost(r.Host)
|
||||
|
|
|
@ -286,6 +286,18 @@ func TestNewNetHTTPHandlerFuncRequests(t *testing.T) {
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"nil body is handled",
|
||||
func() *http.Request {
|
||||
req, _ := http.NewRequest("GET", "https://localhost:8080", nil)
|
||||
return req
|
||||
},
|
||||
func(t *testing.T) func(ctx *fasthttp.RequestCtx) {
|
||||
return func(ctx *fasthttp.RequestCtx) {
|
||||
assert.Equal(t, 0, len(ctx.Request.Body()))
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in New Issue