Home  >  Article  >  Backend Development  >  How to Use Proxies with UTLS and HTTP 1.1 Requests?

How to Use Proxies with UTLS and HTTP 1.1 Requests?

Susan Sarandon
Susan SarandonOriginal
2024-11-19 11:29:03449browse

How to Use Proxies with UTLS and HTTP 1.1 Requests?

Use Proxies with UTLS and HTTP 1.1 Requests

Question:

How do you connect to a host using UTLS with a randomized TLS fingerprint while utilizing an HTTP or SOCKS5 proxy?

Answer:

To use proxies with UTLS and HTTP 1.1 requests, you can follow these steps:

1. Create a Proxy Dialer:

First, create a proxy dialer that will dial the proxy and return a net.Conn. Here's a simplified example:

import (
    "net/url"
    "github.com/magisterquis/connectproxy"
    "golang.org/x/net/proxy"
)

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, _ = proxy.SOCKS5("tcp", proxyString, nil, proxy.Direct)
    case "http":
        proxyDialer, _ = connectproxy.New(proxyURI, proxy.Direct)
    }

    return proxyDialer.Dial("tcp", addr)
}

2. Dial the Proxy and Create a UTLS Client:

Once you have a proxy dialer, dial the proxy to create a net.Conn. Then, use that net.Conn when creating the UTLS Client, before handshaking. For example:

import (
    "github.com/refraction-networking/utls"
)

uconn := utls.UClient(conn, cfg, &utls.HelloRandomizedALPN)

3. Send HTTP Request over UTLS Connection:

Finally, you can use the UTLS connection to send an HTTP 1.1 request. Here's how you can do it:

req := &http.Request{
    Method: "GET",
    URL:    &url.URL{Host: "www.example.com", Path: "/"},
    Header: make(http.Header),
}

req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1

if err := req.Write(uconn); err != nil {
    return nil, err
}

Additional Tips:

  • Consider using the "connectproxy" module for HTTP CONNECT proxies.
  • Explore the Meek pluggable transport source for Tor, which simplifies proxy handling for UTLS and HTTP 1.1 requests.

The above is the detailed content of How to Use Proxies with UTLS and HTTP 1.1 Requests?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn