2019-02-10 16:00:11 +00:00
|
|
|
// 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-23 21:44:31 +00:00
|
|
|
"context"
|
2019-02-10 16:00:11 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2024-05-23 21:44:31 +00:00
|
|
|
func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
|
2019-02-10 16:00:11 +00:00
|
|
|
switch config.Location.Scheme {
|
|
|
|
case "ws":
|
2024-05-23 21:44:31 +00:00
|
|
|
conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
2019-02-10 16:00:11 +00:00
|
|
|
|
|
|
|
case "wss":
|
2024-05-23 21:44:31 +00:00
|
|
|
tlsDialer := &tls.Dialer{
|
|
|
|
NetDialer: dialer,
|
|
|
|
Config: config.TlsConfig,
|
|
|
|
}
|
2019-02-10 16:00:11 +00:00
|
|
|
|
2024-05-23 21:44:31 +00:00
|
|
|
conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
2019-02-10 16:00:11 +00:00
|
|
|
default:
|
|
|
|
err = ErrBadScheme
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|