MCPcopy
hub / github.com/coder/websocket / Pipe

Function Pipe

internal/test/wstest/pipe.go:17–35  ·  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 Pipe(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 = &_dialOpts
29 dialOpts.HTTPClient = &http.Client{
30 Transport: tt,
31 }
32
33 clientConn, _, _ = websocket.Dial(context.Background(), "ws://example.com", dialOpts)
34 return clientConn, serverConn
35}
36
37type fakeTransport struct {
38 h http.HandlerFunc

Callers 2

newConnTestFunction · 0.92
TestConcurrentClosePingFunction · 0.92

Calls 2

AcceptFunction · 0.92
DialFunction · 0.92

Tested by 2

newConnTestFunction · 0.74
TestConcurrentClosePingFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…