Documentation
¶
Overview ¶
Package httpx provides a shared HTTP retry helper for the providers that hit external, potentially rate-limited government APIs (Opendatasoft, data.gouv.fr). It retries transient failures (429/5xx) with exponential backoff and jitter, honoring a numeric Retry-After header when present.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultRetryPolicy = retry.DefaultRetryPolicy
DefaultRetryPolicy re-exports retry.DefaultRetryPolicy for convenience within this package.
Functions ¶
func Do ¶
func Do(ctx context.Context, client *http.Client, policy RetryPolicy, newReq func(context.Context) (*http.Request, error)) (*http.Response, error)
Do executes an HTTP request built by newReq, retrying on 429/5xx responses and transient network errors according to policy. newReq is called once per attempt (never reusing a *http.Request across attempts, since a consumed request body cannot be safely resent) and must build its request against the ctx it is given.
Retries honor a numeric Retry-After header when the server sends one, otherwise back off exponentially with full jitter, capped at policy.MaxDelay. A ctx cancellation or deadline is never retried and aborts immediately. When every attempt is exhausted, the last response (if any) or error is returned as-is, so the caller's usual status/decode handling applies unchanged.
Types ¶
type RetryPolicy ¶
RetryPolicy is an alias for retry.Policy: the configuration type lives in the public retry package so external consumers can construct one (e.g. for a provider's WithRetryPolicy option), while the retry logic below (backoff, jitter, Retry-After handling) stays an internal implementation detail.