diff --git a/proxy.go b/proxy.go index c332633..e9a4cd0 100644 --- a/proxy.go +++ b/proxy.go @@ -15,6 +15,13 @@ import ( "strings" ) +// // proxyDialerEx extends the generated proxy_Dialer +type proxyDialerEx interface { + proxy_Dialer + // UsesTLS indicates whether we expect to dial to a TLS proxy + UsesTLS() bool +} + type netDialerFunc struct { fn func(network, addr string) (net.Conn, error) usesTLS bool @@ -30,11 +37,11 @@ func (ndf *netDialerFunc) UsesTLS() bool { func init() { proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) { - return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial, usesTLS: forwardDialer.UsesTLS()}, nil + return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial, usesTLS: false}, nil }) proxy_RegisterDialerType("https", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) { fwd := forwardDialer.Dial - if !forwardDialer.UsesTLS() { + if dialerEx, ok := forwardDialer.(proxyDialerEx); !ok || !dialerEx.UsesTLS() { tlsDialer := &tls.Dialer{ Config: &tls.Config{}, NetDialer: &net.Dialer{}, diff --git a/x_net_proxy.go b/x_net_proxy.go index f05a113..2e668f6 100644 --- a/x_net_proxy.go +++ b/x_net_proxy.go @@ -27,10 +27,6 @@ func (proxy_direct) Dial(network, addr string) (net.Conn, error) { return net.Dial(network, addr) } -func (proxy_direct) UsesTLS() bool { - return false -} - // A PerHost directs connections to a default Dialer unless the host name // requested matches one of a number of exceptions. type proxy_PerHost struct { @@ -63,10 +59,6 @@ func (p *proxy_PerHost) Dial(network, addr string) (c net.Conn, err error) { return p.dialerForRequest(host).Dial(network, addr) } -func (p *proxy_PerHost) UsesTLS() bool { - return p.def.UsesTLS() || p.bypass.UsesTLS() -} - func (p *proxy_PerHost) dialerForRequest(host string) proxy_Dialer { if ip := net.ParseIP(host); ip != nil { for _, net := range p.bypassNetworks { @@ -169,8 +161,6 @@ func (p *proxy_PerHost) AddHost(host string) { type proxy_Dialer interface { // Dial connects to the given address via the proxy. Dial(network, addr string) (c net.Conn, err error) - // UsesTLS indicates whether we expect to dial to a TLS proxy - UsesTLS() bool } // Auth contains authentication parameters that specific Dialers may require. @@ -348,10 +338,6 @@ func (s *proxy_socks5) Dial(network, addr string) (net.Conn, error) { return conn, nil } -func (s *proxy_socks5) UsesTLS() bool { - return s.forward.UsesTLS() -} - // connect takes an existing connection to a socks5 proxy server, // and commands the server to extend that connection to target, // which must be a canonical address with a host and port.