diff --git a/relay/client/dialer/ws/ws.go b/relay/client/dialer/ws/ws.go index c1d1f74f1..90175ebf9 100644 --- a/relay/client/dialer/ws/ws.go +++ b/relay/client/dialer/ws/ws.go @@ -4,9 +4,12 @@ import ( "context" "fmt" "net" + "net/http" log "github.com/sirupsen/logrus" "nhooyr.io/websocket" + + nbnet "github.com/netbirdio/netbird/util/net" ) func Dial(address string) (net.Conn, error) { @@ -21,7 +24,8 @@ func Dial(address string) (net.Conn, error) { url := fmt.Sprintf("ws://%s:%d", addr.IP.String(), addr.Port) opts := &websocket.DialOptions{ - Host: hostName, + Host: hostName, + HTTPClient: httpClientNbDialer(), } wsConn, _, err := websocket.Dial(context.Background(), url, opts) @@ -34,3 +38,17 @@ func Dial(address string) (net.Conn, error) { return conn, nil } + +func httpClientNbDialer() *http.Client { + customDialer := nbnet.NewDialer() + + customTransport := &http.Transport{ + DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + return customDialer.DialContext(ctx, network, addr) + }, + } + + return &http.Client{ + Transport: customTransport, + } +}