newrelic / go-agent

New Relic Go Agent
Apache License 2.0
762 stars 294 forks source link

transaction.go reqBody(req *http.Request) turn nil body into non Nil body for request.Body == http.NoBody #822

Closed milhoan closed 9 months ago

milhoan commented 9 months ago

Description

We use gorilla middleware, which calls txn.SetWebRequestHTTP(r), which calls

https://github.com/newrelic/go-agent/blob/0e521dc894ec887e31125067f28bd3992cf33310/v3/newrelic/transaction.go#L221

This function causes nil request.Body to be set to non nil request.Body, but with zero length. When our handler function receives the request later, it breaks.

Create mux with a handler function after setting the nrgorilla middleware on the mux Make a request using http.NoBody as the request.Body payload, then access the request.Body inside the handler function.

Expected Behavior

request.Body of type http.NoBody should remain nil or set to http.NoBody. it should have have empty zero length io.Reader created and set on it. Doing so breaks http handlers that check for nil / http.NoBody

NR Diag results

Your Environment

Reproduction case

Additional context

nr-swilloughby commented 9 months ago

Fixed in PR 824