Home >Backend Development >Golang >How to Establish UTLS Connections via HTTP 1.1 Proxy?
When establishing UTLS connections, you may encounter the need to utilize a proxy, such as an HTTP or SOCKS5 proxy. To achieve this, you can leverage the following strategies:
First, you'll need to create a custom proxy dialer function. This function takes the form of dialTLS(network, addr string, _ *tls.Config) (net.Conn, error). Using this function, you can dial the proxy to establish a net.Conn. Afterward, use the net.Conn to create a UTLS client before performing the handshake.
Below is an example of how your custom dialTLS function could look:
import ( "crypto/tls" "net" "net/url" "github.com/magisterquis/connectproxy" "golang.org/x/net/proxy" utls "github.com/refraction-networking/utls" ) var proxyString = "http://127.0.0.1:8080" dialTLS := func(network, addr string, _ *tls.Config) (net.Conn, error) { proxyURI, _ := url.Parse(proxyString) var proxyDialer proxy.Dialer switch proxyURI.Scheme { case "socks5": proxyDialer, err = proxy.SOCKS5("tcp", proxyString, nil, proxy.Direct) case "http": proxyDialer, err = connectproxy.New(proxyURI, proxy.Direct) } conn, err := proxyDialer.Dial("tcp", addr) uconn := utls.UClient(conn, cfg, &utls.HelloRandomizedALPN) // ... continue handshake and request }
Here are a few additional tips:
The above is the detailed content of How to Establish UTLS Connections via HTTP 1.1 Proxy?. For more information, please follow other related articles on the PHP Chinese website!