Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for nil body in http_helper.HttpDoOptions before reading #1370

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be helpful to add a test to monitor null values in options.Body to avoid future regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will be on it.

// 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