Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 20 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ func (r *Request) Do(ctx ...context.Context) *Response {
if r.error != nil {
return r.newErrorResponse(r.error)
}
if r.retryOption != nil && r.retryOption.MaxRetries != 0 && r.unReplayableBody != nil { // retryable request should not have unreplayable Body
if r.retryOption != nil &&
r.retryOption.MaxRetries != 0 &&
!r.retryOption.SkipCheckingBody &&
r.unReplayableBody != nil { // retryable request should not have unreplayable Body
return r.newErrorResponse(errRetryableWithUnReplayableBody)
}
resp, _ := r.do()
Expand Down Expand Up @@ -1229,6 +1232,22 @@ func (r *Request) AddRetryCondition(condition RetryConditionFunc) *Request {
return r
}

// EnableSkipCheckingBody skips checking for an unreplayable body to allow the
// caller to handle the body explicitly on retries.
func (r *Request) EnableSkipCheckingBody() *Request {
ro := r.getRetryOption()
ro.SkipCheckingBody = true
return r
}

// DisableSkipCheckingBody enables checking for an unreplayable body to protect
// the caller from mishandling the body.
func (r *Request) DisableSkipCheckingBody() *Request {
ro := r.getRetryOption()
ro.SkipCheckingBody = false
return r
}

// SetClient change the client of request dynamically.
func (r *Request) SetClient(client *Client) *Request {
if client != nil {
Expand Down
2 changes: 2 additions & 0 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type retryOption struct {
GetRetryInterval GetRetryIntervalFunc
RetryConditions []RetryConditionFunc
RetryHooks []RetryHookFunc
SkipCheckingBody bool
}

func (ro *retryOption) Clone() *retryOption {
Expand All @@ -52,6 +53,7 @@ func (ro *retryOption) Clone() *retryOption {
o := &retryOption{
MaxRetries: ro.MaxRetries,
GetRetryInterval: ro.GetRetryInterval,
SkipCheckingBody: ro.SkipCheckingBody,
}
o.RetryConditions = append(o.RetryConditions, ro.RetryConditions...)
o.RetryHooks = append(o.RetryHooks, ro.RetryHooks...)
Expand Down