http_client

package module
v0.0.0-...-6a0d788 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 14 Imported by: 0

README

http_client

This libary provides a "Golang Functional Options Pattern" implementation for the "net/http" client.

Supported options are:

Option Function
Debug Print debugging info to provided logger.
UserAgent Change the UserAgent header, if not set.
Timeout Set the client request timeout.
DisableHttp2 Disable HTTP2 connections.
Http2Transport Configure HTTP2 transport.
AutoDeflate Disable automatic deflation of gzip responses.
DisableCompression Remove Accept-Encoding: gzip header; and don't deflate responses.
AuthProxy Add auth proxy headers to requests.
BasicAuth Set basic auth header.
BearerAuth Set bearer auth header.
BearerAuthWithRefresh Set bearer auth header, with refresh from file.
DialContext Configure alternative DialContext function.
MaxIdleConnsPerHost Configure MaxIdleConnsPerHost.
Proxy Configure Proxy.
TLSClientCertificate Use provided ClientCertificate function to determine what tls certificate to use for client authentication.
TLSDynamicClientCertificate Use provided DynamicClientCertificateSource to dynamically determine what tls certificate to use for client authentication, also closes existing connections when needed.
TLSRootCAs Use provided CertPool to verify the server certificate.
TLSDynamicRootCAs Use provided DynamicRootCAsSource to dynamically verify the server certificate.
TLSEnableSni Set SNI ServerName based on the request Host field.
TLSInsecureSkipVerify Insecure TLS skip verify
TLSTime Set Time function to use for TLS, usefull for testing.
--- ---
StartDynamicFileClientCertificateSource Start a dynamic file-backed Client Certificate source that can be provided to TLSDynamicClientCertificate
StartDynamicFileRootCAsSource Start a dynamic file-backed Client RootCA source that can be provided to TLSDynamicRootCAs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(options ...Option) (*http.Client, error)

Types

type ClientBuilder

type ClientBuilder []Option

func (ClientBuilder) Add

func (cb ClientBuilder) Add(options ...Option) ClientBuilder

func (ClientBuilder) Complete

func (cb ClientBuilder) Complete() (*http.Client, error)

type DynamicClientCertificateSource

type DynamicClientCertificateSource func(state *OptionState) dynamic_clientcert.DynamicClientCertificate

func StartDynamicFileClientCertificateSource

func StartDynamicFileClientCertificateSource(ctx context.Context, log logr.Logger, certFile, keyFile string) (DynamicClientCertificateSource, context.CancelFunc)

type DynamicRootCAsSource

type DynamicRootCAsSource func(state *OptionState) dynamic_rootca.DynamicRootCAs

func StartDynamicFileRootCAsSource

func StartDynamicFileRootCAsSource(ctx context.Context, log logr.Logger, rootCAFile string) (DynamicRootCAsSource, context.CancelFunc)

type Option

type Option func(state *OptionState) error

func AuthProxy

func AuthProxy(username string, groups []string, extra map[string][]string) Option

func AutoDeflate

func AutoDeflate(enable bool) Option

func BasicAuth

func BasicAuth(username, password string) Option

func BearerAuth

func BearerAuth(bearer string) Option

func BearerAuthWithRefresh

func BearerAuthWithRefresh(bearer string, tokenFile string) Option

func Debug

func Debug(log logr.Logger) Option

func DefaultClient

func DefaultClient() Option

func DefaultTransport

func DefaultTransport() Option

func DialContext

func DialContext(fn func(ctx context.Context, network, addr string) (net.Conn, error)) Option

func DisableCompression

func DisableCompression(disable bool) Option

func EnableHttp2

func EnableHttp2(enabled bool) Option

func EnableOption

func EnableOption(enable bool, option Option) Option

func ManualClient

func ManualClient(client *http.Client) Option

Copys all the fields of the provided client, except for the Transport, which is skipped.

func ManualCloneRequest

func ManualCloneRequest() Option

func ManualTransport

func ManualTransport(transport *http.Transport) Option

func MaxIdleConnsPerHost

func MaxIdleConnsPerHost(maxIdleConnsPerHost int) Option

func Proxy

func Proxy(proxy func(*http.Request) (*url.URL, error)) Option

func RoundTripper

func RoundTripper(fn func(http.RoundTripper) (http.RoundTripper, error)) Option

func TLSClientCertificate

func TLSClientCertificate(fn func(*tls.CertificateRequestInfo) (*tls.Certificate, error)) Option

func TLSDynamicClientCertificate

func TLSDynamicClientCertificate(fn DynamicClientCertificateSource) Option

func TLSDynamicRootCAs

func TLSDynamicRootCAs(fn DynamicRootCAsSource) Option

func TLSEnableSni

func TLSEnableSni() Option

func TLSInsecureSkipVerify

func TLSInsecureSkipVerify(insecureSkipVerify bool) Option

func TLSRenegotation

func TLSRenegotation(renegotiationSupport tls.RenegotiationSupport) Option

func TLSRootCAs

func TLSRootCAs(rootCAs *x509.CertPool) Option

func TLSTime

func TLSTime(time func() time.Time) Option

func Timeout

func Timeout(timeout time.Duration) Option

func UserAgent

func UserAgent(userAgent string) Option

type OptionState

type OptionState struct {
	Dynamic *roundtrippers.DynamicTransportTripper
	Client  *http.Client
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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