Documentation ¶
Overview ¶
Package pac2http provides a convenient interface to build a http proxy from a proxy auto config file
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DirectDialer = &net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }
DirectDialer is the net.Dialer used for direct connection and forwarding to proxy servers
Functions ¶
func ProxyStringFromPac ¶
func ProxyStringFromPac(findProxyForURL func(string, string) (string, error)) func(string) (string, error)
ProxyStringFromPac takes a thread-safe FindProxyForURL(url string, hostname string) (string, error) function, returns a func(string) (string, error), which return "DIRECT" for DIRECT or string url for proxy.
func TransportProxyFromPac ¶
func TransportProxyFromPac(findProxyForURL func(string, string) (string, error)) func(*url.URL) (*url.URL, error)
TransportProxyFromPac takes a thread-safe FindProxyForURL(url string, hostname string) (string, error) function, returns a func(*url.URL) (*url.URL, error), which return nil for DIRECT or *url.URL for proxy.
Types ¶
type PacProxyDialer ¶
type PacProxyDialer struct { ProxyFunc func(string) (string, error) DialerMap cache.LoadingCache //[string]Dialer, "DIRECT" or a URL string ProxyCache cache.LoadingCache // [string]Dialer }
PacProxyDialer implements net.Dialer interface which uses pac file to determine the underlying Dialer to use
func NewPacProxyDialer ¶
func NewPacProxyDialer(proxyFunc func(string) (string, error), cacheOptions ...cache.Option) *PacProxyDialer
NewPacProxyDialer creates an instance of PacProxyDialer with given proxy function
func (*PacProxyDialer) DialContext ¶
func (p *PacProxyDialer) DialContext(ctx context.Context, network string, hostname string) (net.Conn, error)
DialContext works like net.Dialer.DialContext for a PacProxyDialer
type PacProxyHTTPServer ¶
type PacProxyHTTPServer struct { Proxy *goproxy.ProxyHttpServer PacParser *gopac.Parser // contains filtered or unexported fields }
PacProxyHTTPServer implements http.Handler interface which acts as a http proxy and serve traffic using the pac file
func NewPacProxyHTTPServer ¶
func NewPacProxyHTTPServer(parser *gopac.Parser) *PacProxyHTTPServer
NewPacProxyHTTPServer creates an instance of PacProxyHTTPServer with the given initialised gopac.Parser.
func NewPacProxyHTTPServerWithPath ¶
func NewPacProxyHTTPServerWithPath(path string) (*PacProxyHTTPServer, error)
NewPacProxyHTTPServerWithPath is a convenience function to create an instance of PacProxyHTTPServer with a local PAC file.
func NewPacProxyHTTPServerWithURL ¶
func NewPacProxyHTTPServerWithURL(url string) (*PacProxyHTTPServer, error)
NewPacProxyHTTPServerWithURL is a convenience function to create an instance of PacProxyHTTPServer with a remote PAC URL.
func (*PacProxyHTTPServer) GetProxy ¶
GetProxy converts the pac to a proxy function usable for Transport.Proxy
func (*PacProxyHTTPServer) GetProxyFunc ¶
func (svr *PacProxyHTTPServer) GetProxyFunc() func(string) (string, error)
GetProxyFunc converts the pac to a proxy function, used by PacProxyDialer to give a net.Dialer.Dial function
func (*PacProxyHTTPServer) ServeHTTP ¶
func (svr *PacProxyHTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
type StringOrError ¶
StringOrError represents either a string or error
func PacEntryToProxyString ¶
func PacEntryToProxyString(entry string) []*StringOrError
PacEntryToProxyString converts a pac entry string to a *StringOrError array containing "DIRECT", or a proxy url string, or an error