Skip to content

Commit

Permalink
fix: retry duplicates query parameters #938 (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jan 5, 2025
1 parent caa2b42 commit 29797dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,6 @@ func (r *Request) Execute(method, url string) (res *Response, err error) {
}()

r.Method = method
r.URL = url

if r.RetryCount < 0 {
r.RetryCount = 0 // default behavior is no retry
Expand All @@ -1318,6 +1317,7 @@ func (r *Request) Execute(method, url string) (res *Response, err error) {
for i := 0; i <= r.RetryCount; i++ {
r.Attempt++
err = nil
r.URL = url
res, err = r.client.execute(r)
if err != nil {
if irErr, ok := err.(*invalidRequestError); ok {
Expand Down
29 changes: 29 additions & 0 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,35 @@ func TestRetryRequestPostIoReadSeeker(t *testing.T) {
assertEqual(t, "", resp.String())
}

func TestRetryQueryParamsGH938(t *testing.T) {
ts := createGetServer(t)
defer ts.Close()

expectedQueryParams := "foo=baz&foo=bar&foo=bar"

c := dcnl().
SetBaseURL(ts.URL).
SetRetryCount(5).
SetRetryWaitTime(10 * time.Millisecond).
SetRetryMaxWaitTime(20 * time.Millisecond).
AddRetryCondition(
func(r *Response, _ error) bool {
assertEqual(t, expectedQueryParams, r.Request.RawRequest.URL.RawQuery)
return true // always retry
},
)

_, _ = c.R().
SetQueryParamsFromValues(map[string][]string{
"foo": {
"baz",
"bar",
"bar",
},
}).
Get("/set-retrycount-test")
}

func TestRetryCoverage(t *testing.T) {
t.Run("apply retry default min and max value", func(t *testing.T) {
backoff := newBackoffWithJitter(0, 0)
Expand Down

0 comments on commit 29797dd

Please sign in to comment.