forward

package
v0.0.0-...-3f1871c Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: MIT, Apache-2.0 Imports: 10 Imported by: 0

README

forward Build Status GoDoc API Core Coverage Status Go Report Card

forward package implements the default HTTP and WebSocket traffic forwarder for vinxi.

This package is part of the vinxi's core.

The current implementation is a fork of oxy/forward.

Installation

go get -u gopkg.in/vinxi/forward.v0

API

See godoc reference.

License

Apache License 2.0

Documentation

Overview

Package forward implements http handler that forwards requests to remote server and serves back the response. websocket proxying support based on https://github.com/yhat/wsutil

Index

Constants

View Source
const (
	// XForwardedProto stores the forwarder proto header key.
	XForwardedProto = "X-Forwarded-Proto"
	// XForwardedFor stores the forwar for header key.
	XForwardedFor = "X-Forwarded-For"
	// XForwardedHost stores the forward host header key.
	XForwardedHost = "X-Forwarded-Host"
	// XForwardedServer stores the forward server header key.
	XForwardedServer = "X-Forwarded-Server"
	// Connection stores the connection header key.
	Connection = "Connection"
	// KeepAlive stores the keep alive header key.
	KeepAlive = "Keep-Alive"
	// ProxyAuthenticate stores the proxy header key.
	ProxyAuthenticate = "Proxy-Authenticate"
	// ProxyAuthorization stores the proxy authorization header key.
	ProxyAuthorization = "Proxy-Authorization"
	// Te stores the proxy TE header key.
	Te = "Te" // canonicalized version of "TE"
	// Trailers stores the trailers header key.
	Trailers = "Trailers"
	// TransferEncoding stores the transfer encoding header key.
	TransferEncoding = "Transfer-Encoding"
	// Upgrade stores the update header key.
	Upgrade = "Upgrade"
	// ContentLength stores the content length header key.
	ContentLength = "Content-Length"
)

Variables

HopHeaders stores the hop-by-hop headers. These are removed when sent to the backend. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

Functions

func To

func To(uri string) func(w http.ResponseWriter, r *http.Request)

To returns an http.HandlerFunc that forwards the incoming request to the given URI server.

Types

type Forwarder

type Forwarder struct {
	// contains filtered or unexported fields
}

Forwarder wraps two traffic forwarding implementations: HTTP and websockets. It decides based on the specified request which implementation to use

func New

func New(setters ...OptSetter) (*Forwarder, error)

New creates an instance of Forwarder based on the provided list of configuration options

func (*Forwarder) ServeHTTP

func (f *Forwarder) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP decides which forwarder to use based on the specified request and delegates to the proper implementation

type HeaderRewriter

type HeaderRewriter struct {
	TrustForwardHeader bool
	Hostname           string
}

HeaderRewriter is responsible for removing hop-by-hop headers and setting forwarding headers.

func (*HeaderRewriter) Rewrite

func (rw *HeaderRewriter) Rewrite(req *http.Request)

Rewrite rewrites the given request removing hop-by-hop headers and setting forwarding headers.

type OptSetter

type OptSetter func(f *Forwarder) error

OptSetter represents the forwarder setter function.

func ErrorHandler

func ErrorHandler(h utils.ErrorHandler) OptSetter

ErrorHandler is a functional argument that sets error handler of the server

func Logger

func Logger(l utils.Logger) OptSetter

Logger specifies the logger to use. Forwarder will default to utils.NullLogger if no logger has been specified

func PassHostHeader

func PassHostHeader(b bool) OptSetter

PassHostHeader specifies if a client's Host header field should be delegated

func Rewriter

func Rewriter(r ReqRewriter) OptSetter

Rewriter defines a request rewriter for the HTTP forwarder

func RoundTripper

func RoundTripper(r http.RoundTripper) OptSetter

RoundTripper sets a new http.RoundTripper Forwarder will use http.DefaultTransport as a default round tripper

func WebsocketRewriter

func WebsocketRewriter(r ReqRewriter) OptSetter

WebsocketRewriter defines a request rewriter for the websocket forwarder

type ReqRewriter

type ReqRewriter interface {
	Rewrite(r *http.Request)
}

ReqRewriter can alter request headers and body

Jump to

Keyboard shortcuts

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