Skip to content

Commit

Permalink
Merge pull request #80 from brandond/add-with-dialer
Browse files Browse the repository at this point in the history
Allow passing a custom client-side dialer
  • Loading branch information
MbolotSuse authored Jul 10, 2024
2 parents 40afe79 + 0655303 commit afe9785
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ func ClientConnect(ctx context.Context, wsURL string, headers http.Header, diale
return nil
}

// ConnectToProxy connect to websocket server
// ConnectToProxy connects to the websocket server.
// Local connections on behalf of the remote host will be dialed using a default net.Dialer.
func ConnectToProxy(rootCtx context.Context, proxyURL string, headers http.Header, auth ConnectAuthorizer, dialer *websocket.Dialer, onConnect func(context.Context, *Session) error) error {
return ConnectToProxyWithDialer(rootCtx, proxyURL, headers, auth, dialer, nil, onConnect)
}

// ConnectToProxyWithDialer connects to the websocket server.
// Local connections on behalf of the remote host will be dialed using the provided Dialer function.
func ConnectToProxyWithDialer(rootCtx context.Context, proxyURL string, headers http.Header, auth ConnectAuthorizer, dialer *websocket.Dialer, localDialer Dialer, onConnect func(context.Context, *Session) error) error {
logrus.WithField("url", proxyURL).Info("Connecting to proxy")

if dialer == nil {
Expand Down Expand Up @@ -57,7 +64,7 @@ func ConnectToProxy(rootCtx context.Context, proxyURL string, headers http.Heade
ctx, cancel := context.WithCancel(rootCtx)
defer cancel()

session := NewClientSession(auth, ws)
session := NewClientSessionWithDialer(auth, ws, localDialer)
defer session.Close()

if onConnect != nil {
Expand Down

0 comments on commit afe9785

Please sign in to comment.