http

package
v0.25.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

+kubebuilder:validation:Optional

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientFromConfig added in v0.13.0

func ClientFromConfig(config HTTPClientConfig) (*http.Client, error)

ClientFromConfig creates http client from already parsed config.

func ClientModule

func ClientModule() fx.Option

ClientModule is an fx module that provides annotated HTTP client.

func HandlerNameMiddleware added in v0.3.0

func HandlerNameMiddleware(handlerName string) func(http.Handler) http.Handler

HandlerNameMiddleware sets handler name in monitoring context.

func ProxyModule

func ProxyModule() fx.Option

ProxyModule returns the fx module that applies the provided proxy configuration.

func ServerModule

func ServerModule() fx.Option

ServerModule is an fx module that provides annotated HTTP Server using the default listener and registers its metrics with the prometheus registry.

Types

type ClientConstructor

type ClientConstructor struct {
	Name          string
	ConfigKey     string
	DefaultConfig HTTPClientConfig
}

ClientConstructor holds fields to create an annotated instance of HTTP client.

func (ClientConstructor) Annotate

func (constructor ClientConstructor) Annotate() fx.Option

Annotate creates an annotated instance of HTTP Client.

type HTTPClientConfig

type HTTPClientConfig struct {
	// Network level keep-alive duration
	NetworkKeepAlive config.Duration `json:"network_keep_alive" validate:"gte=0s" default:"30s"`
	// Timeout for making network connection
	NetworkTimeout config.Duration `json:"network_timeout" validate:"gte=0s" default:"30s"`
	// HTTP client timeout - Timeouts includes connection time, redirects, reading the response etc. 0 = no timeout.
	Timeout config.Duration `json:"timeout" validate:"gte=0s" default:"60s"`
	// Proxy Connect Header - map[string][]string
	ProxyConnectHeader http.Header `json:"proxy_connect_header,omitempty" validate:"omitempty"`
	// TLS Handshake Timeout. 0 = no timeout
	TLSHandshakeTimeout config.Duration `json:"tls_handshake_timeout" validate:"gte=0s" default:"10s"`
	// Expect Continue Timeout. 0 = no timeout.
	ExpectContinueTimeout config.Duration `json:"expect_continue_timeout" validate:"gte=0s" default:"1s"`
	// Response Header Timeout. 0 = no timeout.
	ResponseHeaderTimeout config.Duration `json:"response_header_timeout" validate:"gte=0s" default:"0s"`
	// Idle Connection Timeout. 0 = no timeout.
	IdleConnTimeout config.Duration `json:"idle_connection_timeout" validate:"gte=0s" default:"90s"`
	// SSL key log file (useful for debugging with wireshark)
	KeyLogWriter string `json:"key_log_file"`
	// Client TLS configuration
	ClientTLSConfig tlsconfig.ClientTLSConfig `json:"tls"`
	// Max Idle Connections per host. 0 = no limit.
	MaxIdleConnsPerHost int `json:"max_idle_connections_per_host" validate:"gte=0" default:"5"`
	// Max Idle Connections. 0 = no limit.
	MaxIdleConns int `json:"max_idle_connections" validate:"gte=0" default:"100"`
	// Max Connections Per Host. 0 = no limit.
	MaxConnsPerHost int `json:"max_conns_per_host" validate:"gte=0" default:"0"`
	// Max Response Header Bytes. 0 = no limit.
	MaxResponseHeaderBytes int64 `json:"max_response_header_bytes" validate:"gte=0" default:"0"`
	// Write Buffer Size. 0 = 4KB.
	WriteBufferSize int `json:"write_buffer_size" validate:"gte=0" default:"0"`
	// Read Buffer Size. 0 = 4KB
	ReadBufferSize int `json:"read_buffer_size" validate:"gte=0" default:"0"`
	// Disable Compression
	DisableCompression bool `json:"disable_compression" default:"false"`
	// Use Proxy
	UseProxy bool `json:"use_proxy" default:"false"`
	// Disable HTTP Keep Alives
	DisableKeepAlives bool `json:"disable_keep_alives" default:"false"`
}

HTTPClientConfig holds configuration for HTTP Client. swagger:model +kubebuilder:object:generate=true

func (*HTTPClientConfig) DeepCopy added in v0.1.2

func (in *HTTPClientConfig) DeepCopy() *HTTPClientConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPClientConfig.

func (*HTTPClientConfig) DeepCopyInto added in v0.1.2

func (in *HTTPClientConfig) DeepCopyInto(out *HTTPClientConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type HTTPServerConfig

type HTTPServerConfig struct {
	// Idle timeout
	IdleTimeout config.Duration `json:"idle_timeout" validate:"gte=0s" default:"30s"`
	// Read header timeout
	ReadHeaderTimeout config.Duration `json:"read_header_timeout" validate:"gte=0s" default:"10s"`
	// Read timeout
	ReadTimeout config.Duration `json:"read_timeout" validate:"gte=0s" default:"10s"`
	// Write timeout
	WriteTimeout config.Duration `json:"write_timeout" validate:"gte=0s" default:"45s"`
	// Max header size in bytes
	MaxHeaderBytes int `json:"max_header_bytes" validate:"gte=0" default:"1048576"`
	// Buckets specification in latency histogram
	LatencyBucketsMS []float64 `json:"latency_buckets_ms" validate:"gte=0" default:"[10.0,25.0,100.0,250.0,1000.0]"`
	// Disable HTTP Keep Alives
	DisableHTTPKeepAlives bool `json:"disable_http_keep_alives" default:"false"`
}

HTTPServerConfig holds configuration for HTTP Server. swagger:model +kubebuilder:object:generate=true

func (*HTTPServerConfig) DeepCopy added in v0.1.2

func (in *HTTPServerConfig) DeepCopy() *HTTPServerConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPServerConfig.

func (*HTTPServerConfig) DeepCopyInto added in v0.1.2

func (in *HTTPServerConfig) DeepCopyInto(out *HTTPServerConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Middleware

type Middleware func(next http.RoundTripper) http.RoundTripper

Middleware is signature of all http middleware.

type MiddlewareChain

type MiddlewareChain struct {
	// contains filtered or unexported fields
}

MiddlewareChain holds a chain of middleware.

func (*MiddlewareChain) Chain

func (mwc *MiddlewareChain) Chain(middlewares ...Middleware)

Chain appends provided middleware to the MiddlewareChain. Middleware will be chained based on the order of Invokes.

type ProxyConfig

type ProxyConfig struct {
	HTTPProxy string `json:"http" validate:"omitempty,url|hostname_port"`

	HTTPSProxy string `json:"https" validate:"omitempty,url|hostname_port"`

	NoProxy []string `json:"no_proxy,omitempty" validate:"omitempty,dive,ip|cidr|fqdn|hostname_port"`
}

ProxyConfig holds proxy configuration. This configuration has preference over environment variables HTTP_PROXY, HTTPS_PROXY or NO_PROXY. See <https://pkg.go.dev/golang.org/x/net/http/httpproxy#Config> swagger:model +kubebuilder:object:generate=true

func (*ProxyConfig) DeepCopy added in v0.1.2

func (in *ProxyConfig) DeepCopy() *ProxyConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProxyConfig.

func (*ProxyConfig) DeepCopyInto added in v0.1.2

func (in *ProxyConfig) DeepCopyInto(out *ProxyConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ProxyConstructor

type ProxyConstructor struct {
	ConfigKey     string
	DefaultConfig ProxyConfig
}

ProxyConstructor holds fields used to configure Proxy.

type RoundTripperFunc

type RoundTripperFunc func(*http.Request) (*http.Response, error)

RoundTripperFunc wraps a func to make it into a http.RoundTripper. Similar to http.HandleFunc.

func (RoundTripperFunc) RoundTrip

func (rtf RoundTripperFunc) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Server

type Server struct {
	Server    *http.Server
	Mux       *mux.Router
	Listener  *listener.Listener
	TLSConfig *tls.Config
	// As we are using Gorilla Mux, root handler is registered the last as a catch all
	RootHandler     http.Handler
	RequestCounters *prometheus.CounterVec
	ErrorCounters   *prometheus.CounterVec
	Latencies       *prometheus.HistogramVec
}

Server holds fields for custom HTTP server.

type ServerConstructor

type ServerConstructor struct {
	// Name of http server instance -- empty for main server
	Name string
	// Name of listener instance
	ListenerName string
	// Name of tls config instance
	TLSConfigName string
	// Viper config key/server name
	ConfigKey string
	// Default Server Config
	DefaultConfig HTTPServerConfig
}

ServerConstructor holds fields to create an annotated HTTP Server.

func (ServerConstructor) Annotate

func (constructor ServerConstructor) Annotate() fx.Option

Annotate creates an annotated instance of HTTP Server.

Jump to

Keyboard shortcuts

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