首頁 > 後端開發 > Golang > 如何透過 HTTP 1.1 代理建立 UTLS 連線?

如何透過 HTTP 1.1 代理建立 UTLS 連線?

Susan Sarandon
發布: 2024-11-15 13:29:02
原創
841 人瀏覽過

How to Establish UTLS Connections via HTTP 1.1 Proxy?

Proxied UTLS Connections via HTTP 1.1

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:

  • Consider using the "connectproxy" module if you plan to tunnel through an HTTP CONNECT proxy.
  • Explore the Meek pluggable transport source for Tor. Its 'utls.go' module simplifies the process, including setting up HTTP or HTTP2 transport based on the negotiated ALPN protocol. It currently supports SOCKS but can be adapted for HTTP proxies.

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

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板