{"modulePath":"github.com/bmbstack/caddy","version":"v0.7.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package proxy\n\nPackage proxy is middleware that proxies requests.\n\n## Functions\n\n```go\nfunc RegisterPolicy(name string, policy func() Policy)\n```\nRegisterPolicy adds a custom policy to the proxy.\n\n## Types\n\n```go\ntype HostPool []*UpstreamHost\n```\nHostPool is a collection of UpstreamHosts.\n\n```go\ntype LeastConn struct{}\n```\nLeastConn is a policy that selects the host with the least connections.\n\n```go\nfunc (r *LeastConn) Select(pool HostPool) *UpstreamHost\n```\nSelect 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.\n\n```go\ntype Policy interface {\n\tSelect(pool HostPool) *UpstreamHost\n}\n```\nPolicy decides how a host will be selected from a pool.\n\n```go\ntype Proxy struct {\n\tNext      middleware.Handler\n\tUpstreams []Upstream\n}\n```\nProxy represents a middleware instance that can proxy requests.\n\n```go\nfunc (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)\n```\nServeHTTP satisfies the middleware.Handler interface.\n\n```go\ntype Random struct{}\n```\nRandom is a policy that selects up hosts from a pool at random.\n\n```go\nfunc (r *Random) Select(pool HostPool) *UpstreamHost\n```\nSelect selects an up host at random from the specified pool.\n\n```go\ntype ReverseProxy struct {\n\t// Director must be a function which modifies\n\t// the request into a new request to be sent\n\t// using Transport. Its response is then copied\n\t// back to the original client unmodified.\n\tDirector func(*http.Request)\n\n\t// The transport used to perform proxy requests.\n\t// If nil, http.DefaultTransport is used.\n\tTransport http.RoundTripper\n\n\t// FlushInterval specifies the flush interval\n\t// to flush to the client while copying the\n\t// response body.\n\t// If zero, no periodic flushing is done.\n\tFlushInterval time.Duration\n}\n```\nReverseProxy is an HTTP Handler that takes an incoming request and sends it to another server, proxying the response back to the client.\n\n```go\nfunc NewSingleHostReverseProxy(target *url.URL) *ReverseProxy\n```\nNewSingleHostReverseProxy 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.\n\n```go\nfunc (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extraHeaders http.Header) error\n```\n\n```go\ntype RoundRobin struct {\n\tRobin uint32\n}\n```\nRoundRobin is a policy that selects hosts based on round robin ordering.\n\n```go\nfunc (r *RoundRobin) Select(pool HostPool) *UpstreamHost\n```\nSelect selects an up host from the pool using a round robin ordering scheme.\n\n```go\ntype Upstream interface {\n\t// The path this upstream host should be routed on\n\tFrom() string\n\t// Selects an upstream host to be routed to.\n\tSelect() *UpstreamHost\n}\n```\nUpstream manages a pool of proxy upstream hosts. Select should return a suitable upstream host, or nil if no such hosts are available.\n\n```go\nfunc NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error)\n```\nNewStaticUpstreams parses the configuration input and sets up static upstreams for the proxy middleware.\n\n```go\ntype UpstreamHost struct {\n\t// The hostname of this upstream host\n\tName         string\n\tReverseProxy *ReverseProxy\n\tConns        int64\n\tFails        int32\n\tFailTimeout  time.Duration\n\tUnhealthy    bool\n\tExtraHeaders http.Header\n\tCheckDown    UpstreamHostDownFunc\n}\n```\nUpstreamHost represents a single proxy upstream\n\n```go\nfunc (uh *UpstreamHost) Down() bool\n```\nDown 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.\n\n```go\ntype UpstreamHostDownFunc func(*UpstreamHost) bool\n```\nUpstreamHostDownFunc can be used to customize how Down behaves.\n\n","path":"github.com/bmbstack/caddy/middleware/proxy","name":"proxy","synopsis":"Package proxy is middleware that proxies requests.","isRedistributable":true}
