How to Use Proxies with UTLS and HTTP 1.1 Requests?

Susan Sarandon
Release: 2024-11-19 11:29:03
Original
449 people have browsed it

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)
}
Copy after login

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)
Copy after login

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
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template