Documentation
¶
Overview ¶
Package retry provides opt-in HTTP retries for providers.
Providers never retry. Pass a client from NewHTTPClient as a provider Config.HTTPClient to opt in. Enabling retries authorizes repeated requests and possible duplicate charges: a transient HTTP status does not establish that an operation was not processed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHTTPClient ¶
NewHTTPClient returns a shallow copy of base, http.DefaultClient when nil, whose Transport retries, according to policy, complete responses that providers report as temporary errors: 408, 429, 500, 502, 503, 504 and 529 statuses, except those the body shows to be exhausted quota, authentication, content filter or context overflow failures. A nil policy or MaxAttempts <= 1 disables retries. Only replayable request bodies are resent; replayable means the bytes can be resent, not that the operation is idempotent. Transport failures and response-body errors, including interrupted successful streams, are never retried.
Types ¶
type Policy ¶
type Policy struct {
// MaxAttempts counts the first attempt; 1 or less disables retries.
MaxAttempts int
// Delays grow from InitialDelay by Multiplier up to MaxDelay.
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
// Jitter varies each delay by up to ±25%.
Jitter bool
// RespectRetryAfter uses the server's Retry-After instead, even beyond
// MaxDelay. One beyond MaxRetryAfter, 60s by default, ends retrying with
// the response, whose error reports the wait in RetryAfter.
RespectRetryAfter bool
MaxRetryAfter time.Duration
}
Policy controls retries. Zero durations and multiplier take the DefaultPolicy values.
func DefaultPolicy ¶
func DefaultPolicy() *Policy
DefaultPolicy returns a conservative retry policy for complete retryable HTTP responses. It does not retry network write/read errors because a POST may already have been processed by the provider.