proxy

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 11 Imported by: 4

Documentation

Overview

Package proxy provides methods for creating a proxy programmatically.

Index

Constants

View Source
const (
	// EnvSSLKey defines the name for the environment variable that holds the
	// root SSL key.
	EnvSSLKey = `HYPERFOX_SSL_KEY`
	// EnvSSLCert defines the name for the environment variable that holds the
	// root SSL certificate..
	EnvSSLCert = `HYPERFOX_SSL_CERT`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyWriteCloser

type BodyWriteCloser interface {
	NewWriteCloser(*http.Response) (io.WriteCloser, error)
}

BodyWriteCloser interface returns a io.WriteCloser where a copy of the response body will be written. The io.WriteCloser's Close() method will be called after the body has been written entirely.

destination -> ... -> BodyWriteCloser -> client -> ...

type Director

type Director interface {
	Direct(*http.Request) error
}

Director interface gets a reference of the http.Request sent by an user before sending it to the destination. The Direct() method may modify the client's request.

client -> Director -> destination

type Interceptor

type Interceptor interface {
	Intercept(*http.Response) error
}

Interceptor interface gets a reference of the http.Response sent by the destination before arriving to the client. The Interceptor() method may modify the destination's response.

destination -> Interceptor -> ... -> client -> ...

type Logger

type Logger interface {
	Log(*ProxiedRequest) error
}

Logger interface gets a reference of the ProxiedRequest after the response has been writte to the client.

The Logger() method must not modify any *ProxiedRequest properties.

destination -> ... -> client -> Logger

type ProxiedRequest

type ProxiedRequest struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	Response       *http.Response
}

ProxiedRequest struct provides properties for executing a *http.Request and proxying it into a http.ResponseWriter.

type Proxy

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

Proxy struct provides methods and properties for creating a proxy programatically.

func NewProxy

func NewProxy() *Proxy

NewProxy creates and returns a Proxy reference.

func (*Proxy) AddBodyWriteCloser

func (p *Proxy) AddBodyWriteCloser(wc BodyWriteCloser)

AddBodyWriteCloser appends a struct that satisfies the BodyWriteCloser interface to the list of body write closers.

func (*Proxy) AddDirector

func (p *Proxy) AddDirector(dir Director)

AddDirector appends a struct that satisfies the Director interface to the list of directors.

func (*Proxy) AddInterceptor

func (p *Proxy) AddInterceptor(dir Interceptor)

AddInterceptor appends a struct that satisfies the Interceptor interface to the list of interceptors.

func (*Proxy) AddLogger

func (p *Proxy) AddLogger(dir Logger)

AddLogger appends a struct that satisfies the Logger interface to the list of loggers.

func (*Proxy) Reset

func (p *Proxy) Reset()

Reset clears the list of interfaces.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP catches a client request and proxies it to the destination server, then waits for the server's answer and sends it back to the client.

(this method should not be called directly).

func (*Proxy) Start

func (p *Proxy) Start(addr string) error

Start creates an HTTP proxy server that listens on the given address.

func (*Proxy) StartTLS

func (p *Proxy) StartTLS(addr string) error

StartTLS creates an HTTPs proxy server that listens on the given address.

func (*Proxy) StartUnix added in v1.9.8

func (p *Proxy) StartUnix(proxy string, proxied string) error

StartUnix creates an HTTP proxy server that listens on the proxy unix socket and forwards to proxied unix socket.

type UnixDirector added in v1.9.8

type UnixDirector struct {
	URL string
}

func (UnixDirector) Direct added in v1.9.8

func (d UnixDirector) Direct(req *http.Request) (err error)

Jump to

Keyboard shortcuts

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