Documentation
¶
Overview ¶
Package httpclient collects conventions for the configuration of HTTP clients used across our various codebases.
It is heavily inspired by github.com/hashicorp/go-cleanhttp.
Index ¶
- Constants
- func ApplyRetryPolicy(c *http.Client) *http.Client
- func DefaultClient() *http.Client
- func DefaultPooledClient() *http.Client
- func DefaultPooledRoundTripper() http.RoundTripper
- func DefaultPooledTransport() *http.Transport
- func DefaultRoundTripper() http.RoundTripper
- func PooledEgressRoundTripper(proxy func(*http.Request) (*url.URL, error)) http.RoundTripper
Constants ¶
const ConnectTimeout = 5 * time.Second
Variables ¶
This section is empty.
Functions ¶
func ApplyRetryPolicy ¶
ApplyRetryPolicy wraps an HTTPClient with one that has a retry policy. Currently the retry policy will retry in any of the following scenarios:
- connection errors and timeouts - 429 or 503 responses (Retry-After is respected) - other 5XX responses (except 501)
All other responses are not retried.
With a minimum wait time of 100ms, and a maximum of 4 retries, the inter-retry intervals will be 100ms, 200ms, 400ms, 800ms with the default backoff policy, for a total time of 1500ms (excluding request attempt times).
func DefaultClient ¶
DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.
func DefaultPooledClient ¶
DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).
func DefaultPooledRoundTripper ¶
func DefaultPooledRoundTripper() http.RoundTripper
DefaultPooledRoundTripper returns an http.RoundTripper with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).
func DefaultPooledTransport ¶
DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).
You should usually use DefaultPooledRoundTripper instead. If you do use this (perhaps in order to tweak some of the configuration values) be aware that you will need to handle wrapping it in an OTel transport with `otelhttp.NewTransport` yourself.
func DefaultRoundTripper ¶
func DefaultRoundTripper() http.RoundTripper
DefaultRoundTripper returns an http.RoundTripper with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled. The transport is configured to emit OTel spans.
func PooledEgressRoundTripper ¶
PooledEgressRoundTripper returns an http.RoundTripper designed to call arbitrary 3rd-party endpoints. It accepts a proxy function which in production should point to a suitable egress proxy.
Types ¶
This section is empty.