5
5
"encoding/json"
6
6
"fmt"
7
7
"io"
8
+ "net/http"
8
9
"strings"
9
10
"sync"
10
11
"sync/atomic"
@@ -87,6 +88,7 @@ type SubscriptionClient struct {
87
88
url string
88
89
conn WebsocketConn
89
90
connectionParams map [string ]interface {}
91
+ websocketOptions WebsocketOptions
90
92
context context.Context
91
93
subscriptions map [string ]* subscription
92
94
cancel context.CancelFunc
@@ -138,6 +140,12 @@ func (sc *SubscriptionClient) WithWebSocket(fn func(sc *SubscriptionClient) (Web
138
140
return sc
139
141
}
140
142
143
+ // WithWebSocketOptions provides options to the websocket client
144
+ func (sc * SubscriptionClient ) WithWebSocketOptions (options WebsocketOptions ) * SubscriptionClient {
145
+ sc .websocketOptions = options
146
+ return sc
147
+ }
148
+
141
149
// WithConnectionParams updates connection params for sending to server through GQL_CONNECTION_INIT event
142
150
// It's usually used for authentication handshake
143
151
func (sc * SubscriptionClient ) WithConnectionParams (params map [string ]interface {}) * SubscriptionClient {
@@ -602,7 +610,9 @@ func newWebsocketConn(sc *SubscriptionClient) (WebsocketConn, error) {
602
610
603
611
options := & websocket.DialOptions {
604
612
Subprotocols : []string {"graphql-ws" },
613
+ HTTPClient : sc .websocketOptions .HTTPClient ,
605
614
}
615
+
606
616
c , _ , err := websocket .Dial (sc .GetContext (), sc .GetURL (), options )
607
617
if err != nil {
608
618
return nil , err
@@ -614,3 +624,9 @@ func newWebsocketConn(sc *SubscriptionClient) (WebsocketConn, error) {
614
624
timeout : sc .GetTimeout (),
615
625
}, nil
616
626
}
627
+
628
+ // WebsocketOptions allows implementation agnostic configuration of the websocket client
629
+ type WebsocketOptions struct {
630
+ // HTTPClient is used for the connection.
631
+ HTTPClient * http.Client
632
+ }
0 commit comments