Documentation ¶
Index ¶
- func HeaderRoundTripper(rt http.RoundTripper, headers map[string]string) http.RoundTripper
- type HTTPClientProxySettings
- type HTTPTransportSettings
- type ProxyHeaders
- func (p ProxyHeaders) Headers() http.Header
- func (p ProxyHeaders) MarshalJSON() ([]byte, error)
- func (p ProxyHeaders) MarshalYAML() (interface{}, error)
- func (p *ProxyHeaders) UnmarshalJSON(b []byte) error
- func (p *ProxyHeaders) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (p *ProxyHeaders) Unpack(cfg *config.C) error
- type ProxyURI
- func (p *ProxyURI) MarshalJSON() ([]byte, error)
- func (p *ProxyURI) MarshalYAML() (interface{}, error)
- func (p *ProxyURI) String() string
- func (p *ProxyURI) URI() *url.URL
- func (p *ProxyURI) UnmarshalJSON(b []byte) error
- func (p *ProxyURI) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (p *ProxyURI) Unpack(s string) error
- type TransportOption
- func WithAPMHTTPInstrumentation() TransportOption
- func WithBaseDialer(d transport.Dialer) TransportOption
- func WithForceAttemptHTTP2(b bool) TransportOption
- func WithHTTP2Only(b bool) TransportOption
- func WithHeaderRoundTripper(headers map[string]string) TransportOption
- func WithIOStats(stats transport.IOStatser) TransportOption
- func WithLogger(logger *logp.Logger) TransportOption
- func WithModRoundtripper(w func(http.RoundTripper) http.RoundTripper) TransportOption
- func WithNOProxy() TransportOption
- func WithTransportFunc(fn func(*http.Transport)) TransportOption
- func WithoutProxyEnvironmentVariables() TransportOption
- type WithKeepaliveSettings
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 ¶
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"` IdleConnTimeout time.Duration `config:"idle_connection_timeout" yaml:"idle_connection_timeout,omitempty" json:"idle_connection_timeout,omitempty"` }
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.
type ProxyHeaders ¶
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.
type ProxyURI ¶
ProxyURI is a URL used for proxy serialized as a string.
func NewProxyURIFromString ¶
func NewProxyURIFromURL ¶
func (*ProxyURI) MarshalJSON ¶
MarshalJSON serializes URI as a string.
func (*ProxyURI) MarshalYAML ¶
MarshalYAML serializes URI as a string.
func (*ProxyURI) UnmarshalJSON ¶
UnmarshalJSON unpacks string into an proxy URI.
func (*ProxyURI) UnmarshalYAML ¶
UnmarshalYAML 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.