mirror of https://github.com/gorilla/websocket.git
simplify proxying with tls proxy
This commit is contained in:
parent
d229c9f93d
commit
2a082eee69
|
@ -274,6 +274,14 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||
return nil, nil, err
|
||||
}
|
||||
if proxyURL != nil {
|
||||
if proxyURL.Scheme == "https" {
|
||||
netDial = func(network, addr string) (net.Conn, error) {
|
||||
t := tls.Dialer{}
|
||||
t.Config = d.TLSClientConfig
|
||||
t.NetDialer = &net.Dialer{}
|
||||
return t.DialContext(ctx, network, addr)
|
||||
}
|
||||
}
|
||||
dialer, err := proxy_FromURL(proxyURL, netDialerFunc(netDial))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
|
11
proxy.go
11
proxy.go
|
@ -6,7 +6,6 @@ package websocket
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"net"
|
||||
|
@ -21,20 +20,12 @@ func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
|
|||
return fn(network, addr)
|
||||
}
|
||||
|
||||
type tlsDialer struct {
|
||||
}
|
||||
|
||||
func (t *tlsDialer) Dial(network, addr string) (c net.Conn, err error) {
|
||||
return tls.DialWithDialer(&net.Dialer{}, network, addr, &tls.Config{})
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) {
|
||||
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil
|
||||
})
|
||||
proxy_RegisterDialerType("https", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) {
|
||||
dialer := &tlsDialer{}
|
||||
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: dialer.Dial}, nil
|
||||
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue