MCPcopy
hub / github.com/cloudflare/cloudflared / WSPipe

Function WSPipe

internal/test/wstest.go:17–34  ·  view source on GitHub ↗

Pipe is used to create an in memory connection between two websockets analogous to net.Pipe.

(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions)

Source from the content-addressed store, hash-verified

15// Pipe is used to create an in memory connection
16// between two websockets analogous to net.Pipe.
17func WSPipe(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions) (clientConn, serverConn *websocket.Conn) {
18 tt := fakeTransport{
19 h: func(w http.ResponseWriter, r *http.Request) {
20 serverConn, _ = websocket.Accept(w, r, acceptOpts)
21 },
22 }
23
24 if dialOpts == nil {
25 dialOpts = &websocket.DialOptions{}
26 }
27 dialOpts = &*dialOpts
28 dialOpts.HTTPClient = &http.Client{
29 Transport: tt,
30 }
31
32 clientConn, _, _ = websocket.Dial(context.Background(), "ws://example.com", dialOpts)
33 return clientConn, serverConn
34}
35
36type fakeTransport struct {
37 h http.HandlerFunc

Calls 1

DialMethod · 0.65