proxyutils

package
v0.0.0-...-9155bf6 Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateChainedProxy

func CreateChainedProxy(name string,
	logTrace *log.Logger,
	logDebug *log.Logger,
	logInfo *log.Logger,
	logWarn *log.Logger,
	logError *log.Logger,
	Transport http.RoundTripper, middlewares ...Middleware) http.RoundTripper

returns a http.RoundTripper that calls each middleware in order

func CreateNewResponse

func CreateNewResponse(request *http.Request, content string) *http.Response

func NewRequestError

func NewRequestError(response *http.Response) error

func ReadGzipBody

func ReadGzipBody(header *http.Header, body io.ReadCloser) ([]byte, error)

utility function that reads the bytes from either a request or a response and returns them. Handles gzip compression if present

Types

type ChainContext

type ChainContext map[interface{}]interface{}

used because the golang context stuff is weird...

type Middleware

type Middleware interface {

	// Modifies the request
	RequestModifier(*http.Request, ChainContext) error

	// Modifies the response
	ResponseModifier(*http.Response, ChainContext) error
}

type RedirectorMiddleware

type RedirectorMiddleware struct {

	// in-memory holder of cookies to be applied to the session
	// -> URL is TargetServer
	Cookies http.CookieJar

	// If a Location: header is encountered, use this to figure out how to handle it
	RetargetMap RetargetMap

	// Remote
	TargetServer *url.URL

	// the host:port that the proxy is listening on
	SourceServer *url.URL

	// Set this to something to override the UserAgent sent to the remote site
	UserAgent string
}

RedirectorMiddleware is a reverse proxy that hides details from both the source client and the target server

func NewRedirectorMiddleware

func NewRedirectorMiddleware(source *url.URL, target *url.URL) *RedirectorMiddleware

func (*RedirectorMiddleware) RequestModifier

func (this *RedirectorMiddleware) RequestModifier(request *http.Request, ctx ChainContext) error

this implements the http.RoundTripper interface, but we break a lot of the rules as we modify the request significantly

func (*RedirectorMiddleware) ResponseModifier

func (this *RedirectorMiddleware) ResponseModifier(response *http.Response, ctx ChainContext) error

type RequestError

type RequestError struct {
	Response *http.Response
}

an error that contains a new response to send to the client

func (*RequestError) Error

func (this *RequestError) Error() string

type RequestModifierFunc

type RequestModifierFunc func(*http.Request, ChainContext) error

type ResponseModifierFunc

type ResponseModifierFunc func(*http.Response, ChainContext) error

type RetargetMap

type RetargetMap map[string]*url.URL

RetargetMap is a map that contains utility functions for retargeting HTTP headers from one server to another -> key is the host without the scheme

func (RetargetMap) Add

func (this RetargetMap) Add(source *url.URL, target *url.URL)

Adds a new target mapping (and it's reverse mapping)

func (RetargetMap) Retarget

func (this RetargetMap) Retarget(header *http.Header, name string, defaultUrl *url.URL)

Retargets a header that is only a URL (Location, Referer, etc)

Jump to

Keyboard shortcuts

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