mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 19:45:35 +00:00
8b492b4121
This makes wsconn.Conns somewhat present reasonably when they are the client of an http.Request, rather than just put a placeholder in that field. Updates tailscale/corp#13777 Signed-off-by: David Anderson <danderson@tailscale.com>
33 lines
693 B
Go
33 lines
693 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux || js
|
|
|
|
package derphttp
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net"
|
|
|
|
"nhooyr.io/websocket"
|
|
"tailscale.com/net/wsconn"
|
|
)
|
|
|
|
func init() {
|
|
dialWebsocketFunc = dialWebsocket
|
|
}
|
|
|
|
func dialWebsocket(ctx context.Context, urlStr string) (net.Conn, error) {
|
|
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
|
|
Subprotocols: []string{"derp"},
|
|
})
|
|
if err != nil {
|
|
log.Printf("websocket Dial: %v, %+v", err, res)
|
|
return nil, err
|
|
}
|
|
log.Printf("websocket: connected to %v", urlStr)
|
|
netConn := wsconn.NetConn(context.Background(), c, websocket.MessageBinary, urlStr)
|
|
return netConn, nil
|
|
}
|