Documentation ¶
Overview ¶
Package reverseproxy implements a simple reverse http proxy. It is used to terminate tls in some situations, and generally forward traffic.
Index ¶
- Constants
- func MustParseURL(rawURL string) *url.URL
- func RequestCopy(req *http.Request) *http.Request
- func UpgradeType(h http.Header) string
- type DialOption
- type HTTPRedirect
- type Proxy
- type ProxyOption
- func OptProxyAddHeaderValue(key, value string) ProxyOption
- func OptProxyDeleteHeader(key string) ProxyOption
- func OptProxyLog(log logger.Log) ProxyOption
- func OptProxyResolver(resolver Resolver) ProxyOption
- func OptProxySetHeaderValue(key, value string) ProxyOption
- func OptProxyTracer(tracer webutil.HTTPTracer) ProxyOption
- func OptProxyTransformRequest(tr TransformRequest) ProxyOption
- func OptProxyUpstream(upstream *Upstream) ProxyOption
- type Resolver
- type TransformRequest
- type Upstream
- type UpstreamOption
Constants ¶
const ( // DefaultAddr is the default reverse proxy address. DefaultAddr = ":443" // DefaultUpgradeAddr is the default upgrade address. DefaultUpgradeAddr = ":80" )
const (
// FlagProxyRequest is a logger flag.
FlagProxyRequest = "proxy.request"
)
Variables ¶
This section is empty.
Functions ¶
func MustParseURL ¶
MustParseURL parses a url and panics if it's bad.
func RequestCopy ¶
RequestCopy does a shallow copy of a request.
func UpgradeType ¶
UpgradeType returns the connection upgrade type. This is used by websockt support.
Types ¶
type DialOption ¶
type DialOption = webutil.DialOption
DialOption is a mutator for a net.Dialer.
func OptDialKeepAlive ¶
func OptDialKeepAlive(d time.Duration) DialOption
OptDialKeepAlive sets the dial keep alive duration. Only use this if you know what you're doing, the defaults are typically sufficient.
func OptDialTimeout ¶
func OptDialTimeout(d time.Duration) DialOption
OptDialTimeout sets the dial timeout.
type HTTPRedirect ¶
HTTPRedirect redirects HTTP to HTTPS
func (HTTPRedirect) ServeHTTP ¶
func (hr HTTPRedirect) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP redirects HTTP to HTTPS
type Proxy ¶
type Proxy struct { Headers http.Header Log logger.Log Upstreams []*Upstream Resolver Resolver Tracer webutil.HTTPTracer TransformRequest TransformRequest Timeout time.Duration }
Proxy is a factory for a simple reverse proxy.
type ProxyOption ¶
ProxyOption is a function that mutates a proxy.
func OptProxyAddHeaderValue ¶
func OptProxyAddHeaderValue(key, value string) ProxyOption
OptProxyAddHeaderValue adds a proxy upstream.
func OptProxyDeleteHeader ¶
func OptProxyDeleteHeader(key string) ProxyOption
OptProxyDeleteHeader adds a proxy upstream.
func OptProxyLog ¶
func OptProxyLog(log logger.Log) ProxyOption
OptProxyLog sets the proxy logger, as well as the logger on any upstreams that are configured.
func OptProxyResolver ¶ added in v1.20210517.3
func OptProxyResolver(resolver Resolver) ProxyOption
OptProxyResolver sets the proxy resolver.
func OptProxySetHeaderValue ¶
func OptProxySetHeaderValue(key, value string) ProxyOption
OptProxySetHeaderValue adds a proxy upstream.
func OptProxyTracer ¶
func OptProxyTracer(tracer webutil.HTTPTracer) ProxyOption
OptProxyTracer adds a proxy tracer.
func OptProxyTransformRequest ¶
func OptProxyTransformRequest(tr TransformRequest) ProxyOption
OptProxyTransformRequest sets the `TransformRequest` on a `Proxy`.
func OptProxyUpstream ¶
func OptProxyUpstream(upstream *Upstream) ProxyOption
OptProxyUpstream adds a proxy upstream.
type Resolver ¶
Resolver is a function that takes a request and produces a destination `url.URL`.
func RoundRobinResolver ¶
RoundRobinResolver returns a closure based resolver that rotates through upstreams uniformly.
type TransformRequest ¶
TransformRequest modifies an HTTP request. This is intended to be used during `Proxy.ServeHTTP()` for custom business logic, e.g. checking if a client was included and verified in the request.
type Upstream ¶
type Upstream struct { // Name is the name of the upstream. Name string // Log is a logger agent. Log logger.Log // URL represents the target of the upstream. URL *url.URL // ReverseProxy is what actually forwards requests. ReverseProxy *httputil.ReverseProxy }
Upstream represents a proxyable server.
func NewUpstream ¶
func NewUpstream(target *url.URL, opts ...UpstreamOption) *Upstream
NewUpstream returns a new upstram.
type UpstreamOption ¶
type UpstreamOption func(*Upstream)
UpstreamOption sets upstream options.
func OptUpstreamDial ¶
func OptUpstreamDial(opts ...webutil.DialOption) UpstreamOption
OptUpstreamDial sets the dial options for the upstream.
func OptUpstreamModifyResponse ¶ added in v1.20210517.3
func OptUpstreamModifyResponse(modifyResponse func(*http.Response) error) UpstreamOption
OptUpstreamModifyResponse sets the dial options for the upstream.