mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
Right now there is no way to pass context.Context to websocket.Dial.
In addition, this method can block indefinitely in the NewClient call.
Fixes golang/go#57953.
Change-Id: Ic52d4b8306cd0850e78d683abb1bf11f0d4247ca
GitHub-Last-Rev: 5e8c3a7cba
GitHub-Pull-Request: golang/net#160
Reviewed-on: https://go-review.googlesource.com/c/net/+/463097
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
30 lines
678 B
Go
30 lines
678 B
Go
// 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 (
|
|
"context"
|
|
"crypto/tls"
|
|
"net"
|
|
)
|
|
|
|
func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
|
|
switch config.Location.Scheme {
|
|
case "ws":
|
|
conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
|
|
|
case "wss":
|
|
tlsDialer := &tls.Dialer{
|
|
NetDialer: dialer,
|
|
Config: config.TlsConfig,
|
|
}
|
|
|
|
conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
|
|
default:
|
|
err = ErrBadScheme
|
|
}
|
|
return
|
|
}
|