@@ -8,15 +8,17 @@ import (
8
8
"nhooyr.io/websocket"
9
9
"tailscale.com/derp"
10
10
"tailscale.com/net/wsconn"
11
-
12
- "github.com/coder/coder/coderd/activewebsockets"
13
11
)
14
12
13
+ type HandleWebsocket func (rw http.ResponseWriter , r * http.Request , options * websocket.AcceptOptions , f func (conn * websocket.Conn ))
14
+
15
15
// WithWebsocketSupport returns an http.Handler that upgrades
16
16
// connections to the "derp" subprotocol to WebSockets and
17
17
// passes them to the DERP server.
18
18
// Taken from: https://github.com/tailscale/tailscale/blob/e3211ff88ba85435f70984cf67d9b353f3d650d8/cmd/derper/websocket.go#L21
19
- func WithWebsocketSupport (sockets * activewebsockets.Active , s * derp.Server , base http.Handler ) http.Handler {
19
+ // The accept function is used to accept the websocket connection and allows the caller to
20
+ // also affect the lifecycle of the websocket connection. (Eg. to close the connection on shutdown)
21
+ func WithWebsocketSupport (accept HandleWebsocket , s * derp.Server , base http.Handler ) http.Handler {
20
22
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
21
23
up := strings .ToLower (r .Header .Get ("Upgrade" ))
22
24
@@ -28,7 +30,7 @@ func WithWebsocketSupport(sockets *activewebsockets.Active, s *derp.Server, base
28
30
return
29
31
}
30
32
31
- sockets . Accept (w , r , & websocket.AcceptOptions {
33
+ accept (w , r , & websocket.AcceptOptions {
32
34
Subprotocols : []string {"derp" },
33
35
OriginPatterns : []string {"*" },
34
36
// Disable compression because we transmit WireGuard messages that
0 commit comments