add sni for mws and ws
This commit is contained in:
@@ -176,7 +176,9 @@ func (d *mwsDialer) initSession(ctx context.Context, host string, conn net.Conn,
|
|||||||
urlObj := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
urlObj := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
||||||
if d.tlsEnabled {
|
if d.tlsEnabled {
|
||||||
urlObj.Scheme = "wss"
|
urlObj.Scheme = "wss"
|
||||||
d.options.TLSConfig.ServerName = host
|
if d.md.sni != "" {
|
||||||
|
d.options.TLSConfig.ServerName = d.md.sni
|
||||||
|
}
|
||||||
dialer.TLSClientConfig = d.options.TLSConfig
|
dialer.TLSClientConfig = d.options.TLSConfig
|
||||||
dialer.NetDialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
dialer.NetDialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
client, err := util.NewUTLSWebSocketClient(conn, d.options.TLSConfig, d.md.useH2)
|
client, err := util.NewUTLSWebSocketClient(conn, d.options.TLSConfig, d.md.useH2)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ type metadata struct {
|
|||||||
path string
|
path string
|
||||||
|
|
||||||
useH2 bool
|
useH2 bool
|
||||||
|
sni string
|
||||||
|
|
||||||
handshakeTimeout time.Duration
|
handshakeTimeout time.Duration
|
||||||
readHeaderTimeout time.Duration
|
readHeaderTimeout time.Duration
|
||||||
@@ -80,6 +81,7 @@ func (d *mwsDialer) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
d.md.tcpKeepaliveCount = mdutil.GetInt(md, "tcp.keepalive.count")
|
d.md.tcpKeepaliveCount = mdutil.GetInt(md, "tcp.keepalive.count")
|
||||||
|
|
||||||
d.md.useH2 = mdutil.GetBool(md, "h2")
|
d.md.useH2 = mdutil.GetBool(md, "h2")
|
||||||
|
d.md.sni = mdutil.GetString(md, "sni")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -114,7 +114,9 @@ func (d *wsDialer) Handshake(ctx context.Context, conn net.Conn, options ...dial
|
|||||||
urlObj := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
urlObj := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
||||||
if d.tlsEnabled {
|
if d.tlsEnabled {
|
||||||
urlObj.Scheme = "wss"
|
urlObj.Scheme = "wss"
|
||||||
d.options.TLSConfig.ServerName = host
|
if d.md.sni != "" {
|
||||||
|
d.options.TLSConfig.ServerName = d.md.sni
|
||||||
|
}
|
||||||
dialer.TLSClientConfig = d.options.TLSConfig
|
dialer.TLSClientConfig = d.options.TLSConfig
|
||||||
dialer.NetDialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
dialer.NetDialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
client, err := util.NewUTLSWebSocketClient(conn, d.options.TLSConfig, d.md.useH2)
|
client, err := util.NewUTLSWebSocketClient(conn, d.options.TLSConfig, d.md.useH2)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type metadata struct {
|
|||||||
host string
|
host string
|
||||||
path string
|
path string
|
||||||
useH2 bool
|
useH2 bool
|
||||||
|
sni string
|
||||||
|
|
||||||
handshakeTimeout time.Duration
|
handshakeTimeout time.Duration
|
||||||
readHeaderTimeout time.Duration
|
readHeaderTimeout time.Duration
|
||||||
@@ -68,5 +69,6 @@ func (d *wsDialer) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
d.md.tcpKeepaliveCount = mdutil.GetInt(md, "tcp.keepalive.count")
|
d.md.tcpKeepaliveCount = mdutil.GetInt(md, "tcp.keepalive.count")
|
||||||
|
|
||||||
d.md.useH2 = mdutil.GetBool(md, "h2")
|
d.md.useH2 = mdutil.GetBool(md, "h2")
|
||||||
|
d.md.sni = mdutil.GetString(md, "sni")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user