2018-05-01 23:45:06 +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-07 10:19:58 +00:00
|
|
|
"context"
|
2018-05-01 23:45:06 +00:00
|
|
|
"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) {
|
2018-05-01 23:45:06 +00:00
|
|
|
switch config.Location.Scheme {
|
|
|
|
case "ws":
|
2024-05-07 10:19:58 +00:00
|
|
|
conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
case "wss":
|
2024-05-07 10:19:58 +00:00
|
|
|
tlsDialer := &tls.Dialer{
|
|
|
|
NetDialer: dialer,
|
|
|
|
Config: config.TlsConfig,
|
|
|
|
}
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2024-05-07 10:19:58 +00:00
|
|
|
conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
2018-05-01 23:45:06 +00:00
|
|
|
default:
|
|
|
|
err = ErrBadScheme
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|