Documentation ¶
Overview ¶
Package proxy provides methods for creating a proxy programmatically.
Index ¶
- Constants
- type BodyWriteCloser
- type Director
- type Interceptor
- type Logger
- type ProxiedRequest
- type Proxy
- func (p *Proxy) AddBodyWriteCloser(wc BodyWriteCloser)
- func (p *Proxy) AddDirector(dir Director)
- func (p *Proxy) AddInterceptor(dir Interceptor)
- func (p *Proxy) AddLogger(dir Logger)
- func (p *Proxy) Reset()
- func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *Proxy) SetCustomDNS(server string) error
- func (p *Proxy) Start(addr string) error
- func (p *Proxy) StartSplit(addr string) error
- func (p *Proxy) StartTLS(addr string) error
- func (p *Proxy) Stop()
Constants ¶
const ( // EnvTLSKey defines the name for the environment variable that holds the // root TLS key. EnvTLSKey = `HYPERFOX_TLS_KEY` // EnvTLSCert defines the name for the environment variable that holds the // root TLS certificate.. EnvTLSCert = `HYPERFOX_TLS_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 ¶
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 ¶
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 (*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 ¶
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 ¶
AddLogger appends a struct that satisfies the Logger interface to the list of loggers.
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) SetCustomDNS ¶
SetCustomDNS sets a DNS server that bypasses the OS settings