httpcommon

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 11 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeaderRoundTripper

func HeaderRoundTripper(rt http.RoundTripper, headers map[string]string) http.RoundTripper

HeaderRoundTripper will return a RoundTripper that sets header KVs if the key is not present.

Types

type HTTPClientProxySettings

type HTTPClientProxySettings struct {
	// Proxy URL to use for http connections. If the proxy url is configured,
	// it is used for all connection attempts. All proxy related environment
	// variables are ignored.
	URL *ProxyURI `config:"proxy_url" yaml:"proxy_url,omitempty"`

	// Headers configures additional headers that are send to the proxy
	// during CONNECT requests.
	Headers ProxyHeaders `config:"proxy_headers" yaml:"proxy_headers,omitempty"`

	// Disable HTTP proxy support. Configured URLs and environment variables
	// are ignored.
	Disable bool `config:"proxy_disable" yaml:"proxy_disable,omitempty"`
}

HTTPClientProxySettings provides common HTTP proxy setup support.

Proxy usage will be disabled in general if Disable is set. If URL is not set, the proxy configuration will default to HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.

The default (and zero) value of HTTPClientProxySettings has Proxy support enabled, and will select the proxy per URL based on the environment variables.

func DefaultHTTPClientProxySettings

func DefaultHTTPClientProxySettings() HTTPClientProxySettings

DefaultHTTPClientProxySettings returns the default HTTP proxy setting.

func NewHTTPClientProxySettings

func NewHTTPClientProxySettings(url string, headers map[string]string, disable bool) (*HTTPClientProxySettings, error)

NewHTTPClientProxySettings creates a new proxy settings based on provided proxy information.

func (*HTTPClientProxySettings) ProxyFunc

func (settings *HTTPClientProxySettings) ProxyFunc() func(*http.Request) (*url.URL, error)

ProxyFunc creates a function that can be used with http.Transport in order to configure the HTTP proxy functionality.

func (*HTTPClientProxySettings) Unpack

func (settings *HTTPClientProxySettings) Unpack(cfg *config.C) error

Unpack sets the proxy settings from a config object. Note: Unpack is automatically used by the configuration system if `cfg.Unpack(&x)` is and X contains a field of type HTTPClientProxySettings.

type HTTPTransportSettings

type HTTPTransportSettings struct {
	// TLS provides ssl/tls setup settings
	TLS *tlscommon.Config `config:"ssl" yaml:"ssl,omitempty" json:"ssl,omitempty"`

	// Timeout configures the `(http.Transport).Timeout`.
	Timeout time.Duration `config:"timeout" yaml:"timeout,omitempty" json:"timeout,omitempty"`

	Proxy HTTPClientProxySettings `config:",inline" yaml:",inline"`
}

HTTPTransportSettings provides common HTTP settings for HTTP clients.

func DefaultHTTPTransportSettings

func DefaultHTTPTransportSettings() HTTPTransportSettings

DefaultHTTPTransportSettings returns the default HTTP transport setting.

func (HTTPTransportSettings) Client

func (settings HTTPTransportSettings) Client(opts ...TransportOption) (*http.Client, error)

Client creates a new http.Client with configured Transport. The transport is instrumented using apmhttp.WrapRoundTripper.

func (*HTTPTransportSettings) RoundTripper

func (settings *HTTPTransportSettings) RoundTripper(opts ...TransportOption) (http.RoundTripper, error)

RoundTripper creates a http.RoundTripper for use with http.Client.

The dialers will registers with stats if given. Stats is used to collect metrics for io errors, bytes in, and bytes out.

func (*HTTPTransportSettings) Unpack

func (settings *HTTPTransportSettings) Unpack(cfg *config.C) error

Unpack reads a config object into the settings.

type ProxyHeaders

type ProxyHeaders map[string]string

ProxyHeaders is a headers for proxy serialized as a map[string]string.

func (ProxyHeaders) Headers

func (p ProxyHeaders) Headers() http.Header

URI returns conventional url.URL structure.

func (ProxyHeaders) MarshalJSON

func (p ProxyHeaders) MarshalJSON() ([]byte, error)

MarshalJSON serializes URI as a string.

func (ProxyHeaders) MarshalYAML

func (p ProxyHeaders) MarshalYAML() (interface{}, error)

MarshalYAML serializes URI as a string.

func (*ProxyHeaders) UnmarshalJSON

func (p *ProxyHeaders) UnmarshalJSON(b []byte) error

UnmarshalJSON unpacks string into an proxy URI.

func (*ProxyHeaders) UnmarshalYAML

func (p *ProxyHeaders) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unpacks string into an proxy URI.

func (*ProxyHeaders) Unpack

func (p *ProxyHeaders) Unpack(cfg *config.C) error

Unpack unpacks string into an proxy URI.

type ProxyURI

type ProxyURI url.URL

ProxyURI is a URL used for proxy serialized as a string.

func NewProxyURIFromString

func NewProxyURIFromString(s string) (*ProxyURI, error)

func NewProxyURIFromURL

func NewProxyURIFromURL(u url.URL) *ProxyURI

func (*ProxyURI) MarshalJSON

func (p *ProxyURI) MarshalJSON() ([]byte, error)

MarshalJSON serializes URI as a string.

func (*ProxyURI) MarshalYAML

func (p *ProxyURI) MarshalYAML() (interface{}, error)

MarshalYAML serializes URI as a string.

func (*ProxyURI) String

func (p *ProxyURI) String() string

MarshalJSON serializes URI as a string.

func (*ProxyURI) URI

func (p *ProxyURI) URI() *url.URL

URI returns conventional url.URL structure.

func (*ProxyURI) UnmarshalJSON

func (p *ProxyURI) UnmarshalJSON(b []byte) error

UnmarshalJSON unpacks string into an proxy URI.

func (*ProxyURI) UnmarshalYAML

func (p *ProxyURI) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unpacks string into an proxy URI.

func (*ProxyURI) Unpack

func (p *ProxyURI) Unpack(s string) error

Unpack unpacks string into an proxy URI.

type TransportOption

type TransportOption interface {
	// contains filtered or unexported methods
}

TransportOption are applied to the http.RoundTripper to be build from HTTPTransportSettings.

func WithAPMHTTPInstrumentation

func WithAPMHTTPInstrumentation() TransportOption

WithAPMHTTPInstrumentation insruments the HTTP client via apmhttp.WrapRoundTripper. Custom APM round tripper wrappers can be configured via WithModRoundtripper.

func WithBaseDialer

func WithBaseDialer(d transport.Dialer) TransportOption

WithBaseDialer configures the dialer used for TCP and TLS connections.

func WithForceAttemptHTTP2

func WithForceAttemptHTTP2(b bool) TransportOption

WithForceAttemptHTTP2 sets the `http.Tansport.ForceAttemptHTTP2` field.

func WithHTTP2Only

func WithHTTP2Only(b bool) TransportOption

WithHTTP2Only will ensure that a HTTP 2 only roundtripper is created.

func WithHeaderRoundTripper

func WithHeaderRoundTripper(headers map[string]string) TransportOption

WithHeaderRoundTripper instruments the HTTP client via a custom http.RoundTripper. This RoundTripper will add headers to each request if the key is not present.

func WithIOStats

func WithIOStats(stats transport.IOStatser) TransportOption

WithIOStats instruments the RoundTripper dialers with the given statser, such that bytes in, bytes out, and errors can be monitored.

func WithLogger

func WithLogger(logger *logp.Logger) TransportOption

WithLogger sets the internal logger that will be used to log dial or TCP level errors. Logging at the connection level will only happen if the logger has been set.

func WithModRoundtripper

func WithModRoundtripper(w func(http.RoundTripper) http.RoundTripper) TransportOption

WithModRoundtripper allows customization of the roundtipper.

func WithNOProxy

func WithNOProxy() TransportOption

WithNOProxy disables the configured proxy. Proxy environment variables like HTTP_PROXY and HTTPS_PROXY will have no affect.

func WithTransportFunc

func WithTransportFunc(fn func(*http.Transport)) TransportOption

WithTransportFunc register a custom function that is used to apply custom changes to the net.Transport, when the Client is build.

func WithoutProxyEnvironmentVariables

func WithoutProxyEnvironmentVariables() TransportOption

WithoutProxyEnvironmentVariables disables support for the HTTP_PROXY, HTTPS_PROXY and NO_PROXY envionrment variables. Explicitly configured proxy URLs will still applied.

type WithKeepaliveSettings

type WithKeepaliveSettings struct {
	Disable             bool
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	IdleConnTimeout     time.Duration
}

WithKeepaliveSettings options can be used to modify the Keepalive

Jump to

Keyboard shortcuts

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