Documentation ¶
Overview ¶
Package proxy is middleware that proxies HTTP requests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var InsecureTransport http.RoundTripper = &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }
InsecureTransport is used to facilitate HTTPS proxying when it is OK for upstream to be using a bad certificate, since this transport skips verification.
Functions ¶
func RegisterPolicy ¶
RegisterPolicy adds a custom policy to the proxy.
Types ¶
type LeastConn ¶
type LeastConn struct{}
LeastConn is a policy that selects the host with the least connections.
func (*LeastConn) Select ¶
func (r *LeastConn) Select(pool HostPool) *UpstreamHost
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 Policy ¶
type Policy interface {
Select(pool HostPool) *UpstreamHost
}
Policy decides how a host will be selected from a pool.
type Proxy ¶
type Proxy struct { Next httpserver.Handler Upstreams []Upstream }
Proxy represents a middleware instance that can proxy requests.
type Random ¶
type Random struct{}
Random is a policy that selects up hosts from a pool at random.
func (*Random) Select ¶
func (r *Random) Select(pool HostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type ReverseProxy ¶
type ReverseProxy struct { // Director must be a function which modifies // the request into a new request to be sent // using Transport. Its response is then copied // back to the original client unmodified. Director func(*http.Request) // The transport used to perform proxy requests. // If nil, http.DefaultTransport is used. Transport http.RoundTripper // FlushInterval specifies the flush interval // to flush to the client while copying the // response body. // If zero, no periodic flushing is done. FlushInterval time.Duration }
ReverseProxy is an HTTP Handler that takes an incoming request and sends it to another server, proxying the response back to the client.
func NewSingleHostReverseProxy ¶
func NewSingleHostReverseProxy(target *url.URL, without string) *ReverseProxy
NewSingleHostReverseProxy returns a new ReverseProxy that rewrites URLs to the scheme, host, and base path provided in target. If the target's path is "/base" and the incoming request was for "/dir", the target request will be for /base/dir. Without logic: target's path is "/", incoming is "/api/messages", without is "/api", then the target request will be for /messages.
func (*ReverseProxy) ServeHTTP ¶
func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, respUpdateFn respUpdateFn) error
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
RoundRobin is a policy that selects hosts based on round robin ordering.
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(pool HostPool) *UpstreamHost
Select selects an up host from the pool using a round robin ordering scheme.
type Upstream ¶
type Upstream interface { // The path this upstream host should be routed on From() string // Selects an upstream host to be routed to. Select() *UpstreamHost // Checks if subpath is not an ignored path AllowedPath(string) bool // Is Upstream in transparent mode? Transparent() bool }
Upstream manages a pool of proxy upstream hosts. Select should return a suitable upstream host, or nil if no such hosts are available.
type UpstreamHost ¶
type UpstreamHost struct { Conns int64 // must be first field to be 64-bit aligned on 32-bit systems Name string // hostname of this upstream host ReverseProxy *ReverseProxy Fails int32 FailTimeout time.Duration Unhealthy bool UpstreamHeaders http.Header DownstreamHeaders http.Header CheckDown UpstreamHostDownFunc WithoutPathPrefix string MaxConns int64 }
UpstreamHost represents a single proxy upstream
func (*UpstreamHost) Available ¶
func (uh *UpstreamHost) Available() bool
Available checks whether the upstream host is available for proxying to
func (*UpstreamHost) Down ¶
func (uh *UpstreamHost) Down() bool
Down checks whether the upstream host is down or not. Down will try to use uh.CheckDown first, and will fall back to some default criteria if necessary.
func (*UpstreamHost) Full ¶
func (uh *UpstreamHost) Full() bool
Full checks whether the upstream host has reached its maximum connections
type UpstreamHostDownFunc ¶
type UpstreamHostDownFunc func(*UpstreamHost) bool
UpstreamHostDownFunc can be used to customize how Down behaves.