resetRequestBody replaces req.Body with a fresh reader from req.GetBody. It closes the previous request body before installing the replacement. Callers must ensure req.GetBody is non-nil.
(req *http.Request)
| 192 | // It closes the previous request body before installing the replacement. |
| 193 | // Callers must ensure req.GetBody is non-nil. |
| 194 | func resetRequestBody(req *http.Request) error { |
| 195 | body, err := req.GetBody() |
| 196 | if err != nil { |
| 197 | return err |
| 198 | } |
| 199 | if req.Body != nil { |
| 200 | if err := req.Body.Close(); err != nil { |
| 201 | _ = body.Close() |
| 202 | return err |
| 203 | } |
| 204 | } |
| 205 | req.Body = body |
| 206 | return nil |
| 207 | } |
| 208 | |
| 209 | type recordingBody struct { |
| 210 | inner io.ReadCloser |
no test coverage detected