Skip to content

Commit

Permalink
check if the body in options is nil before reading
Browse files Browse the repository at this point in the history
  • Loading branch information
semihbkgr committed Nov 6, 2023
1 parent bfd6c0a commit 019f932
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions modules/http-helper/http_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,15 @@ func HTTPDoWithRetryWithOptionsE(
t testing.TestingT, options HttpDoOptions, expectedStatus int,
retries int, sleepBetweenRetries time.Duration,
) (string, error) {
// The request body is closed after a request is complete.
// Extract the underlying data and cache it so we can reuse for retried requests
data, err := io.ReadAll(options.Body)
if err != nil {
return "", err
var data []byte
if options.Body != nil {
// The request body is closed after a request is complete.
// Read the underlying data and cache it, so we can reuse for retried requests.
b, err := io.ReadAll(options.Body)
if err != nil {
return "", err
}
data = b
}

options.Body = nil
Expand Down

0 comments on commit 019f932

Please sign in to comment.