Skip to content

Commit

Permalink
Allow specifying a dialer to use when using a proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Oct 5, 2023
1 parent 0912c83 commit f3929d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 8 additions & 2 deletions proxies/http_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@ import (
"time"
)

func NewHttpConnectProxyDialer(addr string, auth *proxy.Auth, timeout time.Duration) *HttpConnectProxyDialer {
func NewHttpConnectProxyDialer(dialer proxy.Dialer, addr string, auth *proxy.Auth, timeout time.Duration) *HttpConnectProxyDialer {
return &HttpConnectProxyDialer{
dialer: dialer,
address: addr,
auth: auth,
timeout: timeout,
}
}

type HttpConnectProxyDialer struct {
dialer proxy.Dialer
address string
auth *proxy.Auth
timeout time.Duration
}

func (self *HttpConnectProxyDialer) Dial(network, addr string) (net.Conn, error) {
c, err := net.Dial(network, self.address)
dialer := self.dialer
if dialer == nil {
dialer = &net.Dialer{Timeout: self.timeout}
}
c, err := dialer.Dial(network, self.address)
if err != nil {
return nil, errors.Wrapf(err, "unable to connect to proxy server at %s", self.address)
}
Expand Down
12 changes: 2 additions & 10 deletions tls/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,12 @@ func DialWithLocalBinding(a address, name, localBinding string, i *identity.Toke
if proxyConf != nil && proxyConf.Type != transport.ProxyTypeNone {
if proxyConf.Type == transport.ProxyTypeHttpConnect {
log.Infof("using http connect proxy at %s", proxyConf.Address)
conn, err := dialer.Dial("tcp", proxyConf.Address)
proxyDialer := proxies.NewHttpConnectProxyDialer(dialer, proxyConf.Address, proxyConf.Auth, timeout)
conn, err := proxyDialer.Dial("tcp", destination)
if err != nil {
return nil, err
}

log.Debug("sending HTTP CONNECT")
proxyDialer := proxies.NewHttpConnectProxyDialer(destination, proxyConf.Auth, timeout)
if err = proxyDialer.Connect(conn, destination); err != nil {
if closeErr := conn.Close(); closeErr != nil {
log.WithError(closeErr).Error("unable to close underlying connection after http connect error")
}
return nil, err
}

tlsConn = tls.Client(conn, tlsCfg)
} else {
return nil, errors.Errorf("unsupported proxy type %s", string(proxyConf.Type))
Expand Down

0 comments on commit f3929d5

Please sign in to comment.