Documentation
¶
Index ¶
- Constants
- Variables
- func CloneBody(b io.ReadCloser) (r io.ReadCloser, body []byte, err error)
- func CloneHeader(h http.Header) http.Header
- func ConfigLogging(conf *LogConfig) error
- func CopyHeader(dst, src http.Header)
- func NewServer(hconf *HandlerConfig, sconf *ServerConfig, em *ExtensionManager) *http.Server
- func SetLoggingBackend(out string) error
- func SetLoggingFormat(format string) error
- func SetLoggingLevel(level string, debug bool) error
- func WriteProxyErrorToResponseBody(ctx *Context, respWriter Writer, httpcode int32, msg string, ...)
- type Cache
- type ConnPool
- type ConnWrapper
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithError(err error)
- func (c *Context) GetContextError() (errType string, err error)
- func (c *Context) IsAborted() bool
- func (c *Context) SetContextErrType(errType string)
- func (c *Context) SetContextError(err error)
- func (c *Context) SetContextErrorWithType(err error, errType string)
- func (c *Context) SetPoolContextErrorWithType(err error, errType string, parentProxy ...string)
- type DefaultDelegate
- func (h *DefaultDelegate) Auth(ctx *Context, rw http.ResponseWriter)
- func (h *DefaultDelegate) BeforeRequest(ctx *Context)
- func (h *DefaultDelegate) BeforeResponse(ctx *Context, i interface{})
- func (h *DefaultDelegate) Connect(ctx *Context, rw http.ResponseWriter)
- func (h *DefaultDelegate) DuringResponse(ctx *Context, i interface{})
- func (h *DefaultDelegate) Finish(ctx *Context, rw http.ResponseWriter)
- func (h *DefaultDelegate) GetConnPool(ctx *Context) ([]randutil.Choice, error)
- func (h *DefaultDelegate) GetExtensionManager() *ExtensionManager
- func (h *DefaultDelegate) ParentProxy(ctx *Context, i interface{}) (*url.URL, error)
- func (h *DefaultDelegate) SetExtensionManager(em *ExtensionManager)
- type Delegate
- type Extension
- type ExtensionManager
- type HandlerConfig
- type LogConfig
- type Proxy
- type ProxyError
- type Proxychannel
- type Reader
- type ReaderWithProtocol
- type ResponseInfo
- type ResponseWrapper
- type ServerConfig
- type TunnelConn
- type TunnelInfo
- type Writer
- type WriterWithLength
- type WriterWithProtocol
Constants ¶
const ( ConnectFail = "CONNECT_FAIL" AuthFail = "AUTH_FAIL" BeforeRequestFail = "BEFORE_REQUEST_FAIL" BeforeResponseFail = "BEFORE_RESPONSE_FAIL" ParentProxyFail = "PARENT_PROXY_FAIL" HTTPDoRequestFail = "HTTP_DO_REQUEST_FAIL" HTTPWriteClientFail = "HTTP_WRITE_CLIENT_FAIL" HTTPSGenerateTLSConfigFail = "HTTPS_GENERATE_TLS_CONFIG_FAIL" HTTPSHijackClientConnFail = "HTTPS_HIJACK_CLIENT_CONN_FAIL" HTTPSWriteEstRespFail = "HTTPS_WRITE_EST_RESP_FAIL" HTTPSTLSClientConnHandshakeFail = "HTTPSTLS_CLIENT_CONN_HANDSHAKE_FAIL" HTTPSReadReqFromBufFail = "HTTPS_READ_REQ_FROM_BUF_FAIL" HTTPSDoRequestFail = "HTTPS_DO_REQUEST_FAIL" HTTPSWriteRespFail = "HTTPS_WRITE_RESP_FAIL" TunnelHijackClientConnFail = "TUNNEL_HIJACK_CLIENT_CONN_FAIL" TunnelDialRemoteServerFail = "TUNNEL_DIAL_REMOTE_SERVER_FAIL" TunnelWriteEstRespFail = "TUNNEL_WRITE_EST_RESP_FAIL" TunnelConnectRemoteFail = "TUNNEL_CONNECT_REMOTE_FAIL" TunnelWriteTargetConnFinish = "TUNNEL_WRITE_TARGET_CONN_FINISH" TunnelWriteClientConnFinish = "TUNNEL_WRITE_CLIENT_CONN_FINISH" PoolGetParentProxyFail = "POOL_GET_PARENT_PROXY_FAIL" PoolReadRemoteFail = "POOL_READ_REMOTE_FAIL" PoolWriteClientFail = "POOL_WRITE_CLIENT_FAIL" PoolGetConnPoolFail = "POOL_GET_CONN_POOL_FAIL" PoolNoAvailableParentProxyFail = "POOL_NO_AVAILABLE_PARENT_PROXY_FAIL" PoolRoundTripFail = "POOL_ROUND_TRIP_FAIL" PoolParentProxyFail = "POOL_PARENT_PROXY_FAIL" PoolHTTPRegularFinish = "POOL_HTTP_REGULAR_FINISH" PoolGetConnFail = "POOL_GET_CONN_FAIL" PoolWriteTargetConnFail = "POOL_WRITE_TARGET_CONN_FAIL" PoolReadTargetFail = "POOL_READ_TARGET_FAIL" HTTPWebsocketDailFail = "HTTP_WEBSOCKET_DAIL_FAIL" HTTPWebsocketHijackFail = "HTTP_WEBSOCKET_HIJACK_FAIL" HTTPWebsocketHandshakeFail = "HTTP_WEBSOCKET_HANDSHAKE_FAIL" HTTPSWebsocketGenerateTLSConfigFail = "HTTPS_WEBSOCKET_GENERATE_TLS_CONFIG_FAIL" HTTPSWebsocketHijackFail = "HTTPS_WEBSOCKET_HIJACK_FAIL" HTTPSWebsocketWriteEstRespFail = "HTTPS_WEBSOCKET_WRITE_EST_RESP_FAIL" HTTPSWebsocketTLSClientConnHandshakeFail = "HTTPS_WEBSOCKET_TLS_CLIENT_CONN_HANDSHAKE_FAIL" HTTPSWebsocketReadReqFromBufFail = "HTTPS_WEBSOCKET_READ_REQ_FROM_BUF_FAIL" HTTPSWebsocketDailFail = "HTTPS_WEBSOCKET_DAIL_FAIL" HTTPSWebsocketHandshakeFail = "HTTPS_WEBSOCKET_HANDSHAKE_FAIL" HTTPRedialCancelTimeout = "HTTP_REDIAL_CANCEL_TIMEOUT" HTTPSRedialCancelTimeout = "HTTPS_REDIAL_CANCEL_TIMEOUT" TunnelRedialCancelTimeout = "TUNNEL_REDIAL_CANCEL_TIMEOUT" )
FailEventType . When a request is aborted, the event should be one of the following.
const ( DefaultLoggerName = "ProxyChannel" DefaultLogTimeFormat = "2006-01-02 15:04:05" DefaultLogLevel = "debug" DefaultLogOut = "stderr" DefaultLogFormat = `[%{time:` + DefaultLogTimeFormat + `}] [%{module}] [%{level}] %{message}` )
Default Settings
const ( NormalMode = iota ConnPoolMode )
Below are the modes supported.
Variables ¶
var Logger *logging.Logger = logging.MustGetLogger(rootLoggerName)
Logger is used to print log in proxychannel
Functions ¶
func CloneBody ¶
func CloneBody(b io.ReadCloser) (r io.ReadCloser, body []byte, err error)
CloneBody deep copy.
func NewServer ¶
func NewServer(hconf *HandlerConfig, sconf *ServerConfig, em *ExtensionManager) *http.Server
NewServer returns an http.Server that defined by user config
func WriteProxyErrorToResponseBody ¶
func WriteProxyErrorToResponseBody(ctx *Context, respWriter Writer, httpcode int32, msg string, optionalPrefix string)
WriteProxyErrorToResponseBody is the standard function to call when errors occur due to this proxy's behavior, which does not include the behavior of parent proxies.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a concurrent map.
type ConnPool ¶
type ConnPool interface { Get() (net.Conn, error) GetWithTimeout(timeout time.Duration) (net.Conn, error) Close() error GetTag() string // get the human readable tag of the remote GetWeight() int // get the weight of this connection pool GetRemoteAddrURL() *url.URL // get the remote addr of this connection pool }
ConnPool .
type Context ¶
type Context struct { Req *http.Request Data map[interface{}]interface{} Hijack bool MITM bool ReqLength int64 RespLength int64 ErrType string Err error Closed bool Lock sync.RWMutex // contains filtered or unexported fields }
Context stores what methods of Delegate would need as input.
func (*Context) AbortWithError ¶
AbortWithError sets Err and abort to true.
func (*Context) GetContextError ¶
GetContextError .
func (*Context) SetContextErrType ¶
SetContextErrType .
func (*Context) SetContextErrorWithType ¶
SetContextErrorWithType .
type DefaultDelegate ¶
type DefaultDelegate struct {
Delegate
}
DefaultDelegate basically does nothing.
func (*DefaultDelegate) Auth ¶
func (h *DefaultDelegate) Auth(ctx *Context, rw http.ResponseWriter)
Auth .
func (*DefaultDelegate) BeforeRequest ¶
func (h *DefaultDelegate) BeforeRequest(ctx *Context)
BeforeRequest .
func (*DefaultDelegate) BeforeResponse ¶
func (h *DefaultDelegate) BeforeResponse(ctx *Context, i interface{})
BeforeResponse .
func (*DefaultDelegate) Connect ¶
func (h *DefaultDelegate) Connect(ctx *Context, rw http.ResponseWriter)
Connect .
func (*DefaultDelegate) DuringResponse ¶
func (h *DefaultDelegate) DuringResponse(ctx *Context, i interface{})
DuringResponse .
func (*DefaultDelegate) Finish ¶
func (h *DefaultDelegate) Finish(ctx *Context, rw http.ResponseWriter)
Finish .
func (*DefaultDelegate) GetConnPool ¶
func (h *DefaultDelegate) GetConnPool(ctx *Context) ([]randutil.Choice, error)
GetConnPool .
func (*DefaultDelegate) GetExtensionManager ¶
func (h *DefaultDelegate) GetExtensionManager() *ExtensionManager
GetExtensionManager .
func (*DefaultDelegate) ParentProxy ¶
func (h *DefaultDelegate) ParentProxy(ctx *Context, i interface{}) (*url.URL, error)
ParentProxy .
func (*DefaultDelegate) SetExtensionManager ¶
func (h *DefaultDelegate) SetExtensionManager(em *ExtensionManager)
SetExtensionManager .
type Delegate ¶
type Delegate interface { GetExtensionManager() *ExtensionManager SetExtensionManager(*ExtensionManager) Connect(ctx *Context, rw http.ResponseWriter) Auth(ctx *Context, rw http.ResponseWriter) BeforeRequest(ctx *Context) BeforeResponse(ctx *Context, i interface{}) ParentProxy(ctx *Context, i interface{}) (*url.URL, error) DuringResponse(ctx *Context, i interface{}) Finish(ctx *Context, rw http.ResponseWriter) GetConnPool(ctx *Context) ([]randutil.Choice, error) }
Delegate defines some extra manipulation on requests set by user.
type Extension ¶
type Extension interface { Setup() error Cleanup() error GetExtensionManager() *ExtensionManager SetExtensionManager(*ExtensionManager) }
Extension python version __init__(self, engine, **kwargs)
type ExtensionManager ¶
type ExtensionManager struct {
// contains filtered or unexported fields
}
ExtensionManager manage extensions
func NewExtensionManager ¶
func NewExtensionManager(m map[string]Extension) *ExtensionManager
NewExtensionManager initialize an extension
func (*ExtensionManager) Cleanup ¶
func (em *ExtensionManager) Cleanup()
Cleanup cleanup all extensions one by one, dont know if the order matters
func (*ExtensionManager) GetExtension ¶
func (em *ExtensionManager) GetExtension(name string) (Extension, error)
GetExtension get extension by name
func (*ExtensionManager) Setup ¶
func (em *ExtensionManager) Setup()
Setup setup all extensions one by one
type HandlerConfig ¶
type HandlerConfig struct { DisableKeepAlive bool Delegate Delegate DecryptHTTPS bool CertCache cert.Cache Transport *http.Transport Mode int }
HandlerConfig .
var DefaultHandlerConfig *HandlerConfig = &HandlerConfig{ DisableKeepAlive: false, Delegate: &DefaultDelegate{}, DecryptHTTPS: false, CertCache: &Cache{}, Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, DialContext: (&net.Dialer{ DualStack: true, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }, }
DefaultHandlerConfig .
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a struct that implements ServeHTTP() method
func NewProxy ¶
func NewProxy(hconf *HandlerConfig, em *ExtensionManager) *Proxy
NewProxy creates a Proxy instance (an HTTP handler)
func (*Proxy) DoRequest ¶
func (p *Proxy) DoRequest(ctx *Context, rw http.ResponseWriter, responseFunc func(*http.Response, error), conn ...interface{})
DoRequest makes a request to remote server as a clent through given proxy, and calls responseFunc before returning the response. The "conn" is needed when it comes to https request, and only one conn is accepted.
type ProxyError ¶
type ProxyError struct { ErrType string `json:"errType"` ErrCode int32 `json:"errCode"` ErrMsg string `json:"errMsg"` }
ProxyError specifies all the possible errors that can occur due to this proxy's behavior, which does not include the behavior of parent proxies.
type Proxychannel ¶
type Proxychannel struct {
// contains filtered or unexported fields
}
Proxychannel is a prxoy server that manages data transmission between http clients and destination servers. With the "Extensions" provided by user, Proxychannel is able to do authentication, communicate with databases, manipulate the requests/responses, etc.
func NewProxychannel ¶
func NewProxychannel(hconf *HandlerConfig, sconf *ServerConfig, m map[string]Extension) *Proxychannel
NewProxychannel returns a new Proxychannel
func (*Proxychannel) Run ¶
func (pc *Proxychannel) Run()
Run launches the ExtensionManager and the HTTP server
type ReaderWithProtocol ¶
type ReaderWithProtocol struct {
// contains filtered or unexported fields
}
ReaderWithProtocol .
type ResponseInfo ¶
ResponseInfo .
type ResponseWrapper ¶
ResponseWrapper is simply a wrapper for http.Response and error.
type ServerConfig ¶
type ServerConfig struct { ProxyAddr string ReadTimeout time.Duration WriteTimeout time.Duration TLSConfig *tls.Config }
ServerConfig .
var DefaultServerConfig *ServerConfig = &ServerConfig{ ProxyAddr: ":8080", ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second, }
DefaultServerConfig .
type TunnelInfo ¶
type TunnelInfo struct { Client net.Conn Target net.Conn Err error ParentProxy *url.URL Pool ConnPool }
TunnelInfo .
type WriterWithLength ¶
type WriterWithLength struct {
// contains filtered or unexported fields
}
WriterWithLength .
type WriterWithProtocol ¶
type WriterWithProtocol struct {
// contains filtered or unexported fields
}
WriterWithProtocol .