Documentation ¶
Index ¶
- Constants
- type ActiveHealthChecks
- type CircuitBreaker
- type Config
- type DialError
- type DialInfo
- type FirstSelection
- type HTTPTransport
- type Handler
- type HeaderHashSelection
- type HealthChecks
- type Host
- type IPHashSelection
- type KeepAlive
- type LeastConnSelection
- type LoadBalancing
- type PassiveHealthChecks
- type RandomChoiceSelection
- type RandomSelection
- type RoundRobinSelection
- type Selector
- type TLSConfig
- type URIHashSelection
- type Upstream
- type UpstreamPool
Constants ¶
const DialInfoCtxKey = caddy.CtxKey("dial_info")
DialInfoCtxKey is used to store a DialInfo in a context.Context.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveHealthChecks ¶
type ActiveHealthChecks struct { Path string `json:"path,omitempty"` Port int `json:"port,omitempty"` Headers http.Header `json:"headers,omitempty"` Interval caddy.Duration `json:"interval,omitempty"` Timeout caddy.Duration `json:"timeout,omitempty"` MaxSize int64 `json:"max_size,omitempty"` ExpectStatus int `json:"expect_status,omitempty"` ExpectBody string `json:"expect_body,omitempty"` // contains filtered or unexported fields }
ActiveHealthChecks holds configuration related to active health checks (that is, health checks which occur in a background goroutine independently).
type CircuitBreaker ¶
CircuitBreaker is a type that can act as an early-warning system for the health checker when backends are getting overloaded.
type Config ¶
type Config struct { Threshold float64 `json:"threshold"` Type string `json:"type"` TripTime string `json:"trip_time"` }
Config represents the configuration of a circuit breaker.
type DialError ¶
type DialError struct {
// contains filtered or unexported fields
}
DialError is an error that specifically occurs in a call to Dial or DialContext.
type DialInfo ¶
type DialInfo struct { // The network to use. This should be one of the // values that is accepted by net.Dial: // https://golang.org/pkg/net/#Dial Network string // The address to dial. Follows the same // semantics and rules as net.Dial. Address string // Host and Port are components of Address, // pre-split for convenience. Host, Port string }
DialInfo contains information needed to dial a connection to an upstream host. This information may be different than that which is represented in a URL (for example, unix sockets don't have a host that can be represented in a URL, but they certainly have a network name and address).
func NewDialInfo ¶
NewDialInfo creates and populates a DialInfo for the given network and address. It splits the address into host and port values if the network type supports them, or uses the whole address as the port if splitting fails.
type FirstSelection ¶
type FirstSelection struct{}
FirstSelection is a policy that selects the first available host.
func (FirstSelection) CaddyModule ¶
func (FirstSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (FirstSelection) Select ¶
func (FirstSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream
Select returns an available host, if any.
type HTTPTransport ¶
type HTTPTransport struct { // TODO: It's possible that other transports (like fastcgi) might be // able to borrow/use at least some of these config fields; if so, // move them into a type called CommonTransport and embed it TLS *TLSConfig `json:"tls,omitempty"` KeepAlive *KeepAlive `json:"keep_alive,omitempty"` Compression *bool `json:"compression,omitempty"` MaxConnsPerHost int `json:"max_conns_per_host,omitempty"` // TODO: NOTE: we use our health check stuff to enforce max REQUESTS per host, but this is connections DialTimeout caddy.Duration `json:"dial_timeout,omitempty"` FallbackDelay caddy.Duration `json:"dial_fallback_delay,omitempty"` ResponseHeaderTimeout caddy.Duration `json:"response_header_timeout,omitempty"` ExpectContinueTimeout caddy.Duration `json:"expect_continue_timeout,omitempty"` MaxResponseHeaderSize int64 `json:"max_response_header_size,omitempty"` WriteBufferSize int `json:"write_buffer_size,omitempty"` ReadBufferSize int `json:"read_buffer_size,omitempty"` RoundTripper http.RoundTripper `json:"-"` }
HTTPTransport is essentially a configuration wrapper for http.Transport. It defines a JSON structure useful when configuring the HTTP transport for Caddy's reverse proxy.
func (HTTPTransport) CaddyModule ¶
func (HTTPTransport) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (HTTPTransport) Cleanup ¶
func (h HTTPTransport) Cleanup() error
Cleanup implements caddy.CleanerUpper and closes any idle connections.
func (*HTTPTransport) Provision ¶
func (h *HTTPTransport) Provision(_ caddy.Context) error
Provision sets up h.RoundTripper with a http.Transport that is ready to use.
func (*HTTPTransport) UnmarshalCaddyfile ¶
func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile deserializes Caddyfile tokens into h.
transport http { read_buffer <size> write_buffer <size> dial_timeout <duration> tls_client_auth <cert_file> <key_file> tls_insecure_skip_verify tls_timeout <duration> keepalive [off|<duration>] keepalive_idle_conns <max_count> }
type Handler ¶
type Handler struct { TransportRaw json.RawMessage `json:"transport,omitempty"` CBRaw json.RawMessage `json:"circuit_breaker,omitempty"` LoadBalancing *LoadBalancing `json:"load_balancing,omitempty"` HealthChecks *HealthChecks `json:"health_checks,omitempty"` Upstreams UpstreamPool `json:"upstreams,omitempty"` FlushInterval caddy.Duration `json:"flush_interval,omitempty"` Headers *headers.Handler `json:"headers,omitempty"` Transport http.RoundTripper `json:"-"` CB CircuitBreaker `json:"-"` }
Handler implements a highly configurable and production-ready reverse proxy.
func (Handler) CaddyModule ¶
func (Handler) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*Handler) UnmarshalCaddyfile ¶
UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
reverse_proxy [<matcher>] [<upstreams...>] { # upstreams to <upstreams...> # load balancing lb_policy <name> [<options...>] lb_try_duration <duration> lb_try_interval <interval> # active health checking health_path <path> health_port <port> health_interval <interval> health_timeout <duration> health_status <status> health_body <regexp> # passive health checking max_fails <num> fail_duration <duration> max_conns <num> unhealthy_status <status> unhealthy_latency <duration> # header manipulation header_up [+|-]<field> [<value|regexp> [<replacement>]] header_down [+|-]<field> [<value|regexp> [<replacement>]] # round trip transport <name> { ... } }
type HeaderHashSelection ¶
type HeaderHashSelection struct {
Field string `json:"field,omitempty"`
}
HeaderHashSelection is a policy that selects a host based on a given request header.
func (HeaderHashSelection) CaddyModule ¶
func (HeaderHashSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (HeaderHashSelection) Select ¶
func (s HeaderHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstream
Select returns an available host, if any.
type HealthChecks ¶
type HealthChecks struct { Active *ActiveHealthChecks `json:"active,omitempty"` Passive *PassiveHealthChecks `json:"passive,omitempty"` }
HealthChecks holds configuration related to health checking.
type Host ¶
type Host interface { // NumRequests returns the numnber of requests // currently in process with the host. NumRequests() int // Fails returns the count of recent failures. Fails() int // Unhealthy returns true if the backend is unhealthy. Unhealthy() bool // CountRequest atomically counts the given number of // requests as currently in process with the host. The // count should not go below 0. CountRequest(int) error // CountFail atomically counts the given number of // failures with the host. The count should not go // below 0. CountFail(int) error // SetHealthy atomically marks the host as either // healthy (true) or unhealthy (false). If the given // status is the same, this should be a no-op and // return false. It returns true if the status was // changed; i.e. if it is now different from before. SetHealthy(bool) (bool, error) }
Host represents a remote host which can be proxied to. Its methods must be safe for concurrent use.
type IPHashSelection ¶
type IPHashSelection struct{}
IPHashSelection is a policy that selects a host based on hashing the remote IP of the request.
func (IPHashSelection) CaddyModule ¶
func (IPHashSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (IPHashSelection) Select ¶
func (IPHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstream
Select returns an available host, if any.
type KeepAlive ¶
type KeepAlive struct { Enabled *bool `json:"enabled,omitempty"` ProbeInterval caddy.Duration `json:"probe_interval,omitempty"` MaxIdleConns int `json:"max_idle_conns,omitempty"` MaxIdleConnsPerHost int `json:"max_idle_conns_per_host,omitempty"` IdleConnTimeout caddy.Duration `json:"idle_timeout,omitempty"` // how long should connections be kept alive when idle }
KeepAlive holds configuration pertaining to HTTP Keep-Alive.
type LeastConnSelection ¶
type LeastConnSelection struct{}
LeastConnSelection is a policy that selects the host with the least active requests. If multiple hosts have the same fewest number, one is chosen randomly. The term "conn" or "connection" is used in this policy name due to its similar meaning in other software, but our load balancer actually counts active requests rather than connections, since these days requests are multiplexed onto shared connections.
func (LeastConnSelection) CaddyModule ¶
func (LeastConnSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (LeastConnSelection) Select ¶
func (LeastConnSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream
Select selects the up host with the least number of connections in the pool. If more than one host has the same least number of connections, one of the hosts is chosen at random.
type LoadBalancing ¶
type LoadBalancing struct { SelectionPolicyRaw json.RawMessage `json:"selection_policy,omitempty"` TryDuration caddy.Duration `json:"try_duration,omitempty"` TryInterval caddy.Duration `json:"try_interval,omitempty"` RetryMatchRaw caddyhttp.RawMatcherSets `json:"retry_match,omitempty"` SelectionPolicy Selector `json:"-"` RetryMatch caddyhttp.MatcherSets `json:"-"` }
LoadBalancing has parameters related to load balancing.
type PassiveHealthChecks ¶
type PassiveHealthChecks struct { MaxFails int `json:"max_fails,omitempty"` FailDuration caddy.Duration `json:"fail_duration,omitempty"` UnhealthyRequestCount int `json:"unhealthy_request_count,omitempty"` UnhealthyStatus []int `json:"unhealthy_status,omitempty"` UnhealthyLatency caddy.Duration `json:"unhealthy_latency,omitempty"` }
PassiveHealthChecks holds configuration related to passive health checks (that is, health checks which occur during the normal flow of request proxying).
type RandomChoiceSelection ¶
type RandomChoiceSelection struct {
Choose int `json:"choose,omitempty"`
}
RandomChoiceSelection is a policy that selects two or more available hosts at random, then chooses the one with the least load.
func (RandomChoiceSelection) CaddyModule ¶
func (RandomChoiceSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*RandomChoiceSelection) Provision ¶
func (r *RandomChoiceSelection) Provision(ctx caddy.Context) error
Provision sets up r.
func (RandomChoiceSelection) Select ¶
func (r RandomChoiceSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream
Select returns an available host, if any.
func (RandomChoiceSelection) Validate ¶
func (r RandomChoiceSelection) Validate() error
Validate ensures that r's configuration is valid.
type RandomSelection ¶
type RandomSelection struct{}
RandomSelection is a policy that selects an available host at random.
func (RandomSelection) CaddyModule ¶
func (RandomSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (RandomSelection) Select ¶
func (r RandomSelection) Select(pool UpstreamPool, request *http.Request) *Upstream
Select returns an available host, if any.
type RoundRobinSelection ¶
type RoundRobinSelection struct {
// contains filtered or unexported fields
}
RoundRobinSelection is a policy that selects a host based on round-robin ordering.
func (RoundRobinSelection) CaddyModule ¶
func (RoundRobinSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*RoundRobinSelection) Select ¶
func (r *RoundRobinSelection) Select(pool UpstreamPool, _ *http.Request) *Upstream
Select returns an available host, if any.
type Selector ¶
type Selector interface {
Select(UpstreamPool, *http.Request) *Upstream
}
Selector selects an available upstream from the pool.
type TLSConfig ¶
type TLSConfig struct { RootCAPool []string `json:"root_ca_pool,omitempty"` // TODO: Should the client cert+key config use caddytls.CertificateLoader modules? ClientCertificateFile string `json:"client_certificate_file,omitempty"` ClientCertificateKeyFile string `json:"client_certificate_key_file,omitempty"` InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"` HandshakeTimeout caddy.Duration `json:"handshake_timeout,omitempty"` }
TLSConfig holds configuration related to the TLS configuration for the transport/client.
type URIHashSelection ¶
type URIHashSelection struct{}
URIHashSelection is a policy that selects a host by hashing the request URI.
func (URIHashSelection) CaddyModule ¶
func (URIHashSelection) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (URIHashSelection) Select ¶
func (URIHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstream
Select returns an available host, if any.
type Upstream ¶
type Upstream struct { Host `json:"-"` Dial string `json:"dial,omitempty"` MaxRequests int `json:"max_requests,omitempty"` // contains filtered or unexported fields }
Upstream bridges this proxy's configuration to the state of the backend host it is correlated with.
func (*Upstream) Available ¶
Available returns true if the remote host is available to receive requests. This is the method that should be used by selection policies, etc. to determine if a backend should be able to be sent a request.