simplify proxying with tls proxy

This commit is contained in:
Philip Hamer 2021-11-29 14:19:00 -05:00
parent d229c9f93d
commit 2a082eee69
No known key found for this signature in database
GPG Key ID: 7F55992EFA6F6C83
2 changed files with 9 additions and 10 deletions

View File

@ -274,6 +274,14 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
return nil, nil, err return nil, nil, err
} }
if proxyURL != nil { 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)) dialer, err := proxy_FromURL(proxyURL, netDialerFunc(netDial))
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -6,7 +6,6 @@ package websocket
import ( import (
"bufio" "bufio"
"crypto/tls"
"encoding/base64" "encoding/base64"
"errors" "errors"
"net" "net"
@ -21,20 +20,12 @@ func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
return fn(network, addr) 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() { func init() {
proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) { proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) {
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil
}) })
proxy_RegisterDialerType("https", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) { proxy_RegisterDialerType("https", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) {
dialer := &tlsDialer{} return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: dialer.Dial}, nil
}) })
} }