proxy

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: MIT Imports: 9 Imported by: 0

README

proxy

Package proxy is a lightweight reverse proxy.

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

View Source
const (
	// FlagProxyRequest is a logger flag.
	FlagProxyRequest logger.Flag = "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.

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 New

func New() *Proxy

New returns a new 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

func (p *Proxy) UpstreamHeaders() http.Header

UpstreamHeaders returns the upstream headers to add to all upstream requests.

func (*Proxy) WithLogger

func (p *Proxy) WithLogger(log *logger.Logger) *Proxy

WithLogger sets a property and returns the proxy reference.

func (*Proxy) WithResolver

func (p *Proxy) WithResolver(resolver Resolver) *Proxy

WithResolver sets a property and returns the proxy reference.

func (*Proxy) WithUpstream

func (p *Proxy) WithUpstream(upstream *Upstream) *Proxy

WithUpstream adds an upstream by URL.

func (*Proxy) WithUpstreamHeader added in v1.1.1

func (p *Proxy) WithUpstreamHeader(key, value string) *Proxy

WithUpstreamHeader adds a single upstream header.

func (*Proxy) WithUpstreamHeaders added in v1.1.1

func (p *Proxy) WithUpstreamHeaders(headers http.Header) *Proxy

WithUpstreamHeaders sets headers to be added to all upstream requests. Note: this will overwrite any existing headers.

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 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 NewUpstream

func NewUpstream(target *url.URL) *Upstream

NewUpstream returns a new upstram.

func (*Upstream) ServeHTTP

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

ServeHTTP

func (*Upstream) WithLogger

func (u *Upstream) WithLogger(log *logger.Logger) *Upstream

WithLogger sets the logger agent for the upstream.

func (*Upstream) WithName

func (u *Upstream) WithName(name string) *Upstream

WithName sets the name field of the upstream.

Jump to

Keyboard shortcuts

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