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:
以上是如何透過 HTTP 1.1 代理建立 UTLS 連線?的詳細內容。更多資訊請關注PHP中文網其他相關文章!