Documentation ¶
Overview ¶
Package proxy 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
- type HTTPRedirect
- type Proxy
- func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (p *Proxy) UpstreamHeaders() http.Header
- func (p *Proxy) WithLogger(log *logger.Logger) *Proxy
- func (p *Proxy) WithResolver(resolver Resolver) *Proxy
- func (p *Proxy) WithUpstream(upstream *Upstream) *Proxy
- func (p *Proxy) WithUpstreamHeader(key, value string) *Proxy
- func (p *Proxy) WithUpstreamHeaders(headers http.Header) *Proxy
- type Resolver
- type ResponseWriter
- func (rw *ResponseWriter) Close() error
- func (rw *ResponseWriter) ContentLength() int
- func (rw *ResponseWriter) Header() http.Header
- func (rw *ResponseWriter) InnerResponse() http.ResponseWriter
- func (rw *ResponseWriter) StatusCode() int
- func (rw *ResponseWriter) Write(b []byte) (int, error)
- func (rw *ResponseWriter) WriteHeader(code int)
- type Upstream
Constants ¶
const ( // FlagProxyRequest is a logger flag. FlagProxyRequest logger.Flag = "proxy.request" )
Variables ¶
This section is empty.
Functions ¶
func MustParseURL ¶
MustParseURL parses a url and panics if it's bad.
Types ¶
type HTTPRedirect ¶
type HTTPRedirect struct{}
HTTPRedirect redirects HTTP to HTTPS
func NewHTTPRedirect ¶
func NewHTTPRedirect() *HTTPRedirect
NewHTTPRedirect returns a new HTTPRedirect which 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 {
// contains filtered or unexported fields
}
Proxy is a factory for a simple reverse proxy.
func (*Proxy) ServeHTTP ¶
func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP is the http entrypoint.
func (*Proxy) UpstreamHeaders ¶ added in v1.1.1
UpstreamHeaders returns the upstream headers to add to all upstream requests.
func (*Proxy) WithLogger ¶
WithLogger sets a property and returns the proxy reference.
func (*Proxy) WithResolver ¶
WithResolver sets a property and returns the proxy reference.
func (*Proxy) WithUpstream ¶
WithUpstream adds an upstream by URL.
func (*Proxy) WithUpstreamHeader ¶ added in v1.1.1
WithUpstreamHeader adds a single upstream header.
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 ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter a better response writer
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter
NewResponseWriter creates a new uncompressed response writer.
func (*ResponseWriter) Close ¶
func (rw *ResponseWriter) Close() error
Close disposes of the response writer.
func (*ResponseWriter) ContentLength ¶
func (rw *ResponseWriter) ContentLength() int
ContentLength returns the content length
func (*ResponseWriter) Header ¶
func (rw *ResponseWriter) Header() http.Header
Header accesses the response header collection.
func (*ResponseWriter) InnerResponse ¶
func (rw *ResponseWriter) InnerResponse() http.ResponseWriter
InnerResponse returns the backing writer.
func (*ResponseWriter) StatusCode ¶
func (rw *ResponseWriter) StatusCode() int
StatusCode returns the status code.
func (*ResponseWriter) Write ¶
func (rw *ResponseWriter) Write(b []byte) (int, error)
Write writes the data to the response.
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(code int)
WriteHeader is actually a terrible name and this writes the status code.
type Upstream ¶
type Upstream struct { // Name is the name of the upstream. Name string // Log is a logger agent. Log *logger.Logger // 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 (*Upstream) ServeHTTP ¶
func (u *Upstream) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP
func (*Upstream) WithLogger ¶
WithLogger sets the logger agent for the upstream.