@@ -99,6 +99,7 @@ type Client struct {
99
99
healthStatus int32
100
100
101
101
trailingHeaderSupport bool
102
+ maxRetries int
102
103
}
103
104
104
105
// Options for New method
@@ -123,6 +124,10 @@ type Options struct {
123
124
// Custom hash routines. Leave nil to use standard.
124
125
CustomMD5 func () md5simd.Hasher
125
126
CustomSHA256 func () md5simd.Hasher
127
+
128
+ // Number of times a request is retried. Defaults to 10 retries if this option is not configured.
129
+ // Set to 1 to disable retries.
130
+ MaxRetries int
126
131
}
127
132
128
133
// Global constants.
@@ -278,6 +283,11 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
278
283
// healthcheck is not initialized
279
284
clnt .healthStatus = unknown
280
285
286
+ clnt .maxRetries = MaxRetry
287
+ if opts .MaxRetries > 0 {
288
+ clnt .maxRetries = opts .MaxRetries
289
+ }
290
+
281
291
// Return.
282
292
return clnt , nil
283
293
}
@@ -590,9 +600,9 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ
590
600
return nil , errors .New (c .endpointURL .String () + " is offline." )
591
601
}
592
602
593
- var retryable bool // Indicates if request can be retried.
594
- var bodySeeker io.Seeker // Extracted seeker from io.Reader.
595
- reqRetry := MaxRetry // Indicates how many times we can retry the request
603
+ var retryable bool // Indicates if request can be retried.
604
+ var bodySeeker io.Seeker // Extracted seeker from io.Reader.
605
+ var reqRetry = c . maxRetries // Indicates how many times we can retry the request
596
606
597
607
if metadata .contentBody != nil {
598
608
// Check if body is seekable then it is retryable.
0 commit comments