Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2ae516

Browse files
authored
derp/derphttp: pass the headers to the websocket dial (#12)
* derp/derphttp: pass the headers to the websocket dial * chore: fix syntax * chore:commit
1 parent 304cd11 commit e2ae516

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

derp/derphttp/derphttp_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (c *Client) preferIPv6() bool {
247247
}
248248

249249
// dialWebsocketFunc is non-nil (set by websocket.go's init) when compiled in.
250-
var dialWebsocketFunc func(ctx context.Context, urlStr string, tlsConfig *tls.Config) (net.Conn, error)
250+
var dialWebsocketFunc func(ctx context.Context, urlStr string, tlsConfig *tls.Config, httpHeader http.Header) (net.Conn, error)
251251

252252
func (c *Client) useWebsockets() bool {
253253
if runtime.GOOS == "js" {
@@ -326,7 +326,7 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
326326
tlsConfig = c.tlsConfig(reg.Nodes[0])
327327
}
328328
c.logf("%s: connecting websocket to %v", caller, urlStr)
329-
conn, err := dialWebsocketFunc(ctx, urlStr, tlsConfig)
329+
conn, err := dialWebsocketFunc(ctx, urlStr, tlsConfig, c.Header)
330330
if err != nil {
331331
c.logf("%s: websocket to %v error: %v", caller, urlStr, err)
332332
return nil, 0, err

derp/derphttp/websocket.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ func init() {
1717
dialWebsocketFunc = dialWebsocket
1818
}
1919

20-
func dialWebsocket(ctx context.Context, urlStr string, tlsConfig *tls.Config) (net.Conn, error) {
20+
func dialWebsocket(ctx context.Context, urlStr string, tlsConfig *tls.Config, httpHeader http.Header) (net.Conn, error) {
2121
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
2222
Subprotocols: []string{"derp"},
23+
HTTPHeader: httpHeader,
2324
HTTPClient: &http.Client{
2425
Transport: &http.Transport{
2526
TLSClientConfig: tlsConfig,

derp/derphttp/websocket_js.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/tls"
1111
"log"
1212
"net"
13+
"net/http"
1314

1415
"nhooyr.io/websocket"
1516
"tailscale.com/net/wsconn"
@@ -19,7 +20,7 @@ func init() {
1920
dialWebsocketFunc = dialWebsocket
2021
}
2122

22-
func dialWebsocket(ctx context.Context, urlStr string, _ *tls.Config) (net.Conn, error) {
23+
func dialWebsocket(ctx context.Context, urlStr string, _ *tls.Config, _ http.Header) (net.Conn, error) {
2324
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
2425
Subprotocols: []string{"derp"},
2526
})

0 commit comments

Comments
 (0)