...
1
2
3
4
5 package websocket
6
7 import (
8 "context"
9 "crypto/tls"
10 "net"
11 )
12
13 func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
14 switch config.Location.Scheme {
15 case "ws":
16 conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
17
18 case "wss":
19 tlsDialer := &tls.Dialer{
20 NetDialer: dialer,
21 Config: config.TlsConfig,
22 }
23
24 conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
25 default:
26 err = ErrBadScheme
27 }
28 return
29 }
30
View as plain text