mirror of https://github.com/gorilla/websocket.git
move to newNetDialerFunc
This commit is contained in:
parent
29bba1ad6c
commit
dc42337df9
14
client.go
14
client.go
|
@ -246,19 +246,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
var netDial netDialerFunc
|
netDial := newNetDialerFunc(u.Scheme, d.NetDial, d.NetDialContext, d.NetDialTLSContext)
|
||||||
switch {
|
|
||||||
case u.Scheme == "https" && d.NetDialTLSContext != nil:
|
|
||||||
netDial = d.NetDialTLSContext
|
|
||||||
case d.NetDialContext != nil:
|
|
||||||
netDial = d.NetDialContext
|
|
||||||
case d.NetDial != nil:
|
|
||||||
netDial = func(ctx context.Context, net, addr string) (net.Conn, error) {
|
|
||||||
return d.NetDial(net, addr)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
netDial = (&net.Dialer{}).DialContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// If needed, wrap the dial function to connect through a proxy.
|
// If needed, wrap the dial function to connect through a proxy.
|
||||||
if d.Proxy != nil {
|
if d.Proxy != nil {
|
||||||
|
|
20
proxy.go
20
proxy.go
|
@ -16,6 +16,26 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func newNetDialerFunc(
|
||||||
|
scheme string,
|
||||||
|
netDial func(network, addr string) (net.Conn, error),
|
||||||
|
netDialContext func(ctx context.Context, network, addr string) (net.Conn, error),
|
||||||
|
netDialTLSContext func(ctx context.Context, network, addr string) (net.Conn, error),
|
||||||
|
) netDialerFunc {
|
||||||
|
switch {
|
||||||
|
case scheme == "https" && netDialTLSContext != nil:
|
||||||
|
return netDialTLSContext
|
||||||
|
case netDialContext != nil:
|
||||||
|
return netDialContext
|
||||||
|
case netDial != nil:
|
||||||
|
return func(ctx context.Context, net, addr string) (net.Conn, error) {
|
||||||
|
return netDial(net, addr)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return (&net.Dialer{}).DialContext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type netDialerFunc func(ctx context.Context, network, addr string) (net.Conn, error)
|
type netDialerFunc func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||||
|
|
||||||
func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
|
func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
|
||||||
|
|
Loading…
Reference in New Issue