@ -15,6 +15,7 @@ import (
uuid "github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"golang.org/x/net/proxy"
)
// client connection
@ -100,8 +101,19 @@ func (connCtx *ConnContext) Id() uuid.UUID {
return connCtx . ClientConn . Id
}
func ( connCtx * ConnContext ) dialer ( network string , addr string ) proxy . ContextDialer {
for _ , addon := range connCtx . proxy . Addons {
dialer := addon . FindDialer ( connCtx , addr )
if dialer != nil {
return dialer
}
}
return & net . Dialer { }
}
func ( connCtx * ConnContext ) initHttpServerConn ( ) {
if connCtx . ServerConn != nil {
log . Infof ( "There was a server conn %v" , connCtx . ServerConn )
return
}
if connCtx . ClientConn . Tls {
@ -120,7 +132,8 @@ func (connCtx *ConnContext) initHttpServerConn() {
Transport : & http . Transport {
Proxy : useProxy ,
DialContext : func ( ctx context . Context , network , addr string ) ( net . Conn , error ) {
c , err := ( & net . Dialer { } ) . DialContext ( ctx , network , addr )
dialer := connCtx . dialer ( network , addr )
c , err := dialer . DialContext ( ctx , network , addr )
if err != nil {
return nil , err
}
@ -159,7 +172,10 @@ func (connCtx *ConnContext) initServerTcpConn(req *http.Request) error {
connCtx . ServerConn = ServerConn
ServerConn . Address = connCtx . pipeConn . host
plainConn , err := getConnFrom ( req . Host , connCtx . proxy . Opts . Upstream )
dialer := connCtx . dialer ( "tcp" , req . Host )
plainConn , err := dialer . DialContext ( context . Background ( ) , "tcp" , req . Host )
if err != nil {
return err
}