func gorillaDialWebsocket(ctx context.Context, urlStr string, tlsConfig *tls.Config, ipAddr string) (jsoncodec.JSONConn, error) {
	url, err := url.Parse(urlStr)
	if err != nil {
		return nil, errors.Trace(err)
	}
	// TODO(rogpeppe) We'd like to set Deadline here
	// but that would break lots of tests that rely on
	// setting a zero timeout.
	netDialer := net.Dialer{}
	dialer := &websocket.Dialer{
		NetDial: func(netw, addr string) (net.Conn, error) {
			if addr == url.Host {
				// Use pre-resolved IP address. The address
				// may be different if a proxy is in use.
				addr = ipAddr
			}
			return netDialer.DialContext(ctx, netw, addr)
		},
		Proxy:            proxy.DefaultConfig.GetProxy,
		HandshakeTimeout: 45 * time.Second,
		TLSClientConfig:  tlsConfig,
	}
	// Note: no extra headers.
	c, resp, err := dialer.Dial(urlStr, nil)
	if err != nil {
		if err == websocket.ErrBadHandshake {
			// If ErrBadHandshake is returned, a non-nil response
			// is returned so the client can react to auth errors
			// (for example).
			defer resp.Body.Close()
			body, readErr := ioutil.ReadAll(resp.Body)
			if readErr == nil {
				err = errors.Errorf(
					"%s (%s)",
					strings.TrimSpace(string(body)),
					http.StatusText(resp.StatusCode),
				)
			}
		}
		return nil, errors.Trace(err)
	}
	return jsoncodec.NewWebsocketConn(c), nil
}
// gorillaDialWebsocket makes a websocket connection using the
// gorilla websocket package. The ipAddr parameter holds the
// actual IP address that will be contacted - the host in urlStr
// is used only for TLS verification when tlsConfig.ServerName
// is empty.
gorillaDialWebsocket makes a websocket connection using the
gorilla websocket package. The ipAddr parameter holds the
actual IP address that will be contacted - the host in urlStr
is used only for TLS verification when tlsConfig.ServerName
is empty.
// gorillaDialWebsocket makes a websocket connection using the // gorilla websocket package . The ipAddr parameter holds the // actual IP address that will be contacted - the host in urlStr // is used only for TLS verification when tlsConfig . ServerName // is empty .
func gorillaDialWebsocket(ctx context.Context, urlStr string, tlsConfig *tls.Config, ipAddr string) (jsoncodec.JSONConn, error) {
	url, err := url.Parse(urlStr)
	if err != nil {
		return nil, errors.Trace(err)
	}
	netDialer := net.Dialer{}
	dialer := &websocket.Dialer{
		NetDial: func(netw, addr string) (net.Conn, error) {
			if addr == url.Host {
				addr = ipAddr
			}
			return netDialer.DialContext(ctx, netw, addr)
		},
		Proxy:            proxy.DefaultConfig.GetProxy,
		HandshakeTimeout: 45 * time.Second,
		TLSClientConfig:  tlsConfig,
	}
	c, resp, err := dialer.Dial(urlStr, nil)
	if err != nil {
		if err == websocket.ErrBadHandshake {
			defer resp.Body.Close()
			body, readErr := ioutil.ReadAll(resp.Body)
			if readErr == nil {
				err = errors.Errorf(
					"%s (%s)",
					strings.TrimSpace(string(body)),
					http.StatusText(resp.StatusCode),
				)
			}
		}
		return nil, errors.Trace(err)
	}
	return jsoncodec.NewWebsocketConn(c), nil
}
func gorillaDialWebsocket ( ctx context . Context , urlStr string , tlsConfig * tls . Config , ipAddr string ) ( jsoncodec . JSONConn , error ) { url , err := url . Parse ( urlStr ) if err != nil { return nil , errors . Trace ( err ) } netDialer := net . Dialer { } dialer := & websocket . Dialer { NetDial : func ( netw , addr string ) ( net . Conn , error ) { if addr == url . Host { addr = ipAddr } return netDialer . DialContext ( ctx , netw , addr ) } , Proxy : proxy . DefaultConfig . GetProxy , HandshakeTimeout : 45 * time . Second , TLSClientConfig : tlsConfig , } c , resp , err := dialer . Dial ( urlStr , nil ) if err != nil { if err == websocket . ErrBadHandshake { defer resp . Body . Close ( ) body , readErr := ioutil . ReadAll ( resp . Body ) if readErr == nil { err = errors . Errorf ( " " , strings . TrimSpace ( string ( body ) ) , http . StatusText ( resp . StatusCode ) , ) } } return nil , errors . Trace ( err ) } return jsoncodec . NewWebsocketConn ( c ) , nil }
gorillaDialWebsocket makes a websocket connection using the
gorilla websocket package.
gorillaDialWebsocket makes a websocket connection using the gorilla websocket package .
// TODO(rogpeppe) We'd like to set Deadline here // but that would break lots of tests that rely on // setting a zero timeout. // Use pre-resolved IP address. The address // may be different if a proxy is in use. // Note: no extra headers. // If ErrBadHandshake is returned, a non-nil response // is returned so the client can react to auth errors // (for example).