httpclient

package
v0.0.0-...-b17460c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
const ConnectTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func ApplyRetryPolicy

func ApplyRetryPolicy(c *http.Client) *http.Client

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

func DefaultClient() *http.Client

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

func DefaultPooledClient() *http.Client

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

func DefaultPooledTransport() *http.Transport

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

func PooledEgressRoundTripper(proxy func(*http.Request) (*url.URL, error)) http.RoundTripper

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL