Skip to content

Commit

Permalink
fix: re-use client TLS config for establishing ws connections
Browse files Browse the repository at this point in the history
- follows work from #3613
  • Loading branch information
frrist authored and frrist committed Mar 28, 2024
1 parent 447fe32 commit 0756652
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/publicapi/client/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"net/url"
"time"

"github.com/bacalhau-project/bacalhau/pkg/lib/concurrency"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"go.uber.org/multierr"

"github.com/bacalhau-project/bacalhau/pkg/lib/concurrency"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
)

// Client is the object that makes transport-level requests to specified APIs.
Expand Down Expand Up @@ -127,10 +128,18 @@ func (c *httpClient) Dial(ctx context.Context, endpoint string, in apimodels.Req
if err != nil {
return nil, err
}

dialer := *websocket.DefaultDialer
httpR.URL.Scheme = "ws"

// if we are using TLS create a TLS config
if c.config.TLS.UseTLS {
httpR.URL.Scheme = "wss"
dialer.TLSClientConfig = getTLSTransport(&c.config).TLSClientConfig
}

// Connect to the server
conn, resp, err := websocket.DefaultDialer.Dial(httpR.URL.String(), httpR.Header)
conn, resp, err := dialer.Dial(httpR.URL.String(), httpR.Header)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0756652

Please sign in to comment.