Skip to content

Commit 29797dd

Browse files
authored
fix: retry duplicates query parameters #938 (#942)
1 parent caa2b42 commit 29797dd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,6 @@ func (r *Request) Execute(method, url string) (res *Response, err error) {
13001300
}()
13011301

13021302
r.Method = method
1303-
r.URL = url
13041303

13051304
if r.RetryCount < 0 {
13061305
r.RetryCount = 0 // default behavior is no retry
@@ -1318,6 +1317,7 @@ func (r *Request) Execute(method, url string) (res *Response, err error) {
13181317
for i := 0; i <= r.RetryCount; i++ {
13191318
r.Attempt++
13201319
err = nil
1320+
r.URL = url
13211321
res, err = r.client.execute(r)
13221322
if err != nil {
13231323
if irErr, ok := err.(*invalidRequestError); ok {

retry_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,35 @@ func TestRetryRequestPostIoReadSeeker(t *testing.T) {
906906
assertEqual(t, "", resp.String())
907907
}
908908

909+
func TestRetryQueryParamsGH938(t *testing.T) {
910+
ts := createGetServer(t)
911+
defer ts.Close()
912+
913+
expectedQueryParams := "foo=baz&foo=bar&foo=bar"
914+
915+
c := dcnl().
916+
SetBaseURL(ts.URL).
917+
SetRetryCount(5).
918+
SetRetryWaitTime(10 * time.Millisecond).
919+
SetRetryMaxWaitTime(20 * time.Millisecond).
920+
AddRetryCondition(
921+
func(r *Response, _ error) bool {
922+
assertEqual(t, expectedQueryParams, r.Request.RawRequest.URL.RawQuery)
923+
return true // always retry
924+
},
925+
)
926+
927+
_, _ = c.R().
928+
SetQueryParamsFromValues(map[string][]string{
929+
"foo": {
930+
"baz",
931+
"bar",
932+
"bar",
933+
},
934+
}).
935+
Get("/set-retrycount-test")
936+
}
937+
909938
func TestRetryCoverage(t *testing.T) {
910939
t.Run("apply retry default min and max value", func(t *testing.T) {
911940
backoff := newBackoffWithJitter(0, 0)

0 commit comments

Comments
 (0)