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)
| 119 | // the connection. The response body may not contain the entire response and does |
| 120 | // not need to be closed by the application. |
| 121 | func 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 ¯\_(ツ)_/¯.) |