Documentation ¶
Index ¶
Constants ¶
View Source
const (
ProtoHttp = "HTTP"
)
Supported ProxyConfig.Protocol protocols.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶ added in v0.3.0
type Context interface { // Connection ID ID() uint64 // Returns Proxy associated with this context. Proxy() Proxy // Client remote address. RemoteAddr() string // Return amount of bytes client sent/received. // // When invoked, bytes are flushed and set to 0. Bytes() uint64 // Done is called when the connection is closed. Done() <-chan struct{} }
type EventHandler ¶ added in v0.3.0
type EventHandler struct { // Connect is invoked on initial connect from remote client. // It receives the remote address of the connecting client. // Returning false will close the connection. Connect func(Context) bool // AuthEvent allows for authorization via remote address or username/password. // Returning false will close the connection with the corresponding response for that protocol. // // If AuthEvent == nil, authorization is disabled. Auth func(Context, AuthEvent) bool // Dial is invoked before dialing the connection to the destination host. // // The host parameter is the original host in which the Dial would connect to. // The string to be returned is the host:port in which you wish the proxy to forward the connection to. Dial func(ctx Context, host string) string // Disconnect is invoked when the client or server closes the connection. Disconnect func(Context) }
type HttpProxy ¶
type HttpProxy struct {
// contains filtered or unexported fields
}
func (*HttpProxy) Config ¶ added in v0.3.0
func (h *HttpProxy) Config() ProxyConfig
type Proxy ¶
type Proxy interface { Start(string) error Close() error Addr() string Config() ProxyConfig }
All proxy protocols implement Proxy interface
func NewProxy ¶
func NewProxy(cfg ProxyConfig) (Proxy, error)
Returns a new Proxy interface with a type specific to ProxyConfig.Protocol.
type ProxyConfig ¶
type ProxyConfig struct { // Proxy Protocol. // // Supported protocols: ProtoHttp. Protocol string // Timeout for dialing connection to destination host. // // Default value: 30 seconds. DialTimeout time.Duration // Timeout for reading from both client and server. // // Default value: 30 seconds. ReadTimeout time.Duration // Timeout for writing to both client and server. // // Default value: 30 seconds. WriteTimeout time.Duration // If true, ErrorHandler logging will be verbose. Debug bool // hop-by-hop headers are to be consumed by a proxy and not sent to the destination server. // // When true, the headers will be forwarded to the destination server. // This can be useful when proxying to another proxy server that will need to handle them. ForwardHopHeaders bool // If true, Proxy will act as a forwarding proxy to another receiving proxy. // // ForwardHopHeaders will be set to true and all requests will be written to the wire in proxy format. Forwarder bool // You can use the EventHandler to register any available events that will be invoked by the Proxy. Events *EventHandler // ErrorHandler receives any returned errors from the Proxy // // This function is called by multiple goroutines and is not thread safe. // If you wish to write to a file or another output that requires thread-safety // use a locking mechanism such as sync.Mutex. ErrorHandler func(error, Context) }
Click to show internal directories.
Click to hide internal directories.