reverseproxy

package
v1.20220411.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 14 Imported by: 0

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

View Source
const (
	// DefaultAddr is the default reverse proxy address.
	DefaultAddr = ":443"
	// DefaultUpgradeAddr is the default upgrade address.
	DefaultUpgradeAddr = ":80"
)
View Source
const (
	// FlagProxyRequest is a logger flag.
	FlagProxyRequest = "proxy.request"
)

Variables

This section is empty.

Functions

func MustParseURL

func MustParseURL(rawURL string) *url.URL

MustParseURL parses a url and panics if it's bad.

func RequestCopy

func RequestCopy(req *http.Request) *http.Request

RequestCopy does a shallow copy of a request.

func UpgradeType

func UpgradeType(h http.Header) string

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

type HTTPRedirect struct {
	RedirectScheme string
	RedirectHost   string
}

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.

func NewProxy

func NewProxy(opts ...ProxyOption) (*Proxy, error)

NewProxy returns a new proxy.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP is the http entrypoint.

type ProxyOption

type ProxyOption func(*Proxy) error

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

type Resolver func(*http.Request, []*Upstream) (*Upstream, error)

Resolver is a function that takes a request and produces a destination `url.URL`.

func RoundRobinResolver

func RoundRobinResolver(upstreams []*Upstream) Resolver

RoundRobinResolver returns a closure based resolver that rotates through upstreams uniformly.

type TransformRequest

type TransformRequest = func(*http.Request)

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.

func (*Upstream) ServeHTTP

func (u *Upstream) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP

func (*Upstream) UseHTTP2

func (u *Upstream) UseHTTP2() error

UseHTTP2 sets the upstream to use http2.

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.

Jump to

Keyboard shortcuts

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