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

Function clientConnect

carrier/websocket.go:121–134  ·  view source on GitHub ↗

clientConnect creates a WebSocket client connection for provided request. Caller is responsible for closing the connection. The response body may not contain the entire response and does not need to be closed by the application.

(req *http.Request, dialler *websocket.Dialer)

Source from the content-addressed store, hash-verified

119// the connection. The response body may not contain the entire response and does
120// not need to be closed by the application.
121func clientConnect(req *http.Request, dialler *websocket.Dialer) (*websocket.Conn, *http.Response, error) {
122 req.URL.Scheme = changeRequestScheme(req.URL)
123 wsHeaders := websocketHeaders(req)
124 if dialler == nil {
125 dialler = &websocket.Dialer{
126 Proxy: http.ProxyFromEnvironment,
127 }
128 }
129 conn, response, err := dialler.Dial(req.URL.String(), wsHeaders)
130 if err != nil {
131 return nil, response, err
132 }
133 return conn, response, nil
134}
135
136// changeRequestScheme is needed as the gorilla websocket library requires the ws scheme.
137// (even though it changes it back to http/https, but ¯\_(ツ)_/¯.)

Callers 4

TestServeFunction · 0.85
TestWebsocketWrapperFunction · 0.85
createWebsocketStreamFunction · 0.85

Calls 4

changeRequestSchemeFunction · 0.85
websocketHeadersFunction · 0.85
DialMethod · 0.65
StringMethod · 0.65

Tested by 2

TestServeFunction · 0.68
TestWebsocketWrapperFunction · 0.68