Documentation ¶
Overview ¶
`http_retry` is a HTTP client-side Tripperware that allows you to retry requests that are marked as idempotent and safe.
This logic works for requests considered safe and idempotent (configurable) and ones that have no body, or have `Request.GetBody` either automatically implemented (`byte.Buffer`, `string.Buffer`) or specified manually. By default all GET, HEAD and OPTIONS requests are considered idempotent and safe.
The implementation allow retries after client-side errors or returned error codes (by default 5**) according to configurable backoff policies (linear backoff by default). Additionally, requests can be hedged. Hedging works by sending additional requests without waiting for a previous one to return.
Index ¶
- func DefaultResponseDiscarder(resp *http.Response) bool
- func DefaultRetriableDecider(req *http.Request) bool
- func Enable(req *http.Request) *http.Request
- func EnableContext(ctx context.Context) context.Context
- func Tripperware(opts ...Option) httpwares.Tripperware
- type BackoffFunc
- type Option
- type RequestRetryDeciderFunc
- type ResponseDiscarderFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultResponseDiscarder ¶
DefaultResponseDiscarder is the default implementation that discards responses in order to try again.
It is fairly conservative and rejects (and thus retries) responses with 500, 503 and 504 status codes. See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_error
func DefaultRetriableDecider ¶
DefaultRetriableDecider is the default implementation that retries only indempotent and safe requests (GET, OPTION, HEAD).
It is fairly conservative and heeds the of http://restcookbook.com/HTTP%20Methods/idempotency.
func Enable ¶
Enable turns on the retry logic for a given request, regardless of what the retry decider says.
Please make sure you do not pass around this request's context.
func EnableContext ¶
Enable turns on the retry logic for a given request's context, regardless of what the retry decider says.
Please make sure you do not pass around this request's context.
func Tripperware ¶
func Tripperware(opts ...Option) httpwares.Tripperware
Tripperware is client side HTTP ware that retries the requests.
Be default this retries safe and idempotent requests 3 times with a linear delay of 100ms. This behaviour can be customized using With* parameter options.
Requests that have `http_retry.Enable` set on them will always be retried.
Types ¶
type BackoffFunc ¶
BackoffFunc denotes a family of functions that controll the backoff duration between call retries.
They are called with an identifier of the attempt, and should return a time the system client should hold off for. If the time returned is longer than the `context.Context.Deadline` of the request the deadline of the request takes precedence and the wait will be interrupted before proceeding with the next iteration.
func BackoffLinear ¶
func BackoffLinear(waitBetween time.Duration) BackoffFunc
BackoffLinear is very simple: it waits for a fixed period of time between calls.
type Option ¶
type Option func(*options)
func WithBackoff ¶
func WithBackoff(bf BackoffFunc) Option
WithBackoff sets the `BackoffFunc `used to control time between retries.
func WithDecider ¶
func WithDecider(f RequestRetryDeciderFunc) Option
WithDecider is a function that allows users to customize the logic that decides whether a request is retriable.
func WithResponseDiscarder ¶
func WithResponseDiscarder(f ResponseDiscarderFunc) Option
WithResponseDiscarder is a function that decides whether a given response should be discarded and another request attempted.
type RequestRetryDeciderFunc ¶
RequestRetryDeciderFunc decides whether the given function is idempotent and safe or to retry.
type ResponseDiscarderFunc ¶
ResponseDiscarderFunc decides when to discard a response and retry the request again (on true).