cloudflared-mirror/vendor/golang.org/x/net/websocket/dial.go

30 lines
678 B
Go
Raw Normal View History

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package websocket
import (
2024-05-07 10:19:58 +00:00
"context"
"crypto/tls"
"net"
)
2024-05-07 10:19:58 +00:00
func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
switch config.Location.Scheme {
case "ws":
2024-05-07 10:19:58 +00:00
conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
case "wss":
2024-05-07 10:19:58 +00:00
tlsDialer := &tls.Dialer{
NetDialer: dialer,
Config: config.TlsConfig,
}
2024-05-07 10:19:58 +00:00
conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
default:
err = ErrBadScheme
}
return
}