Skip to content

Commit 20c534f

Browse files
author
Emi Gutekanst
authored
gateway: benchmark: fix websocket auth (#1132)
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
1 parent 28df838 commit 20c534f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

cmd/src/gateway_benchmark.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Examples:
8383
endpoints["ws(s): sourcegraph"] = &webSocketClient{
8484
conn: nil,
8585
URL: strings.Replace(fmt.Sprint(*sgEndpoint, "/.api/gateway/websocket"), "http", "ws", 1),
86+
headers: http.Header{
87+
"Authorization": []string{"token " + *sgpToken},
88+
},
8689
}
8790
endpoints["http(s): sourcegraph"] = fmt.Sprint(*sgEndpoint, "/.api/gateway/http")
8891
endpoints["http(s): http-then-ws"] = fmt.Sprint(*sgEndpoint, "/.api/gateway/http-then-websocket")
@@ -155,8 +158,9 @@ Examples:
155158
}
156159

157160
type webSocketClient struct {
158-
conn *websocket.Conn
159-
URL string
161+
conn *websocket.Conn
162+
URL string
163+
headers http.Header
160164
}
161165

162166
func (c *webSocketClient) reconnect() error {
@@ -165,7 +169,7 @@ func (c *webSocketClient) reconnect() error {
165169
}
166170
fmt.Println("Connecting to WebSocket..", c.URL)
167171
var err error
168-
c.conn, _, err = websocket.DefaultDialer.Dial(c.URL, nil)
172+
c.conn, _, err = websocket.DefaultDialer.Dial(c.URL, c.headers)
169173
if err != nil {
170174
c.conn = nil // retry again later
171175
return fmt.Errorf("WebSocket dial(%s): %v", c.URL, err)

0 commit comments

Comments
 (0)