8000 How do I send the request using the req module? · Issue #680 · elazarl/goproxy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
How do I send the request using the req module? #680
Open
@tocha688

Description

@tocha688

How do I send the request using the req module?

https://github.com/imroc/req
I need to create a transit server to forward all proxy requests through the req module

package main

/**
正向代理
*/

import (
	"context"
	"log"
	"net"
	"net/http"
	"retls/libs/config"
	"retls/libs/utils"
	"strings"

	"github.com/elazarl/goproxy"
	"github.com/elazarl/goproxy/ext/auth"
	"github.com/imroc/req/v3"
)

type Logger struct {
	goproxy.Logger
}

// Printf implements goproxy.Logger.
func (p Logger) Printf(format string, v ...interface{}) {
	// panic("unimplemented")
}

func main() {
	proxy := goproxy.NewProxyHttpServer()
	proxy.Logger = Logger{}
	proxy.Verbose = true
	auth.ProxyBasic(proxy, "my_realm", func(user, pwd string) bool {
		return user == config.Local.GetString("auth.user") && pwd == config.Local.GetString("auth.pass")
	})
	XPool := &utils.ProxyPool{}
	XPool.LoadFile("assets/proxies.txt")
	proxy.ConnectDialWithReq = func(reqr *http.Request, network, addr string) (net.Conn, error) {
		x := XPool.Next()
		userAgent := reqr.Header.Get("User-Agent")
		client := req.C()
		if userAgent != "" {
			// 设置随机的TLS指纹
			if strings.Contains(strings.ToLower(userAgent), "chrome") {
				client.ImpersonateChrome()
			} else if strings.Contains(strings.ToLower(userAgent), "firefox") {
				client.ImpersonateFirefox()
			} else if strings.Contains(strings.ToLower(userAgent), "safari") {
				client.ImpersonateSafari()
			} else if strings.Contains(strings.ToLower(userAgent), "edge") {
				client.SetTLSFingerprintEdge()
			} else if strings.Contains(strings.ToLower(userAgent), "iphone") || strings.Contains(strings.ToLower(userAgent), "ipad") {
				client.SetTLSFingerprintIOS()
			} else if strings.Contains(strings.ToLower(userAgent), "android") {
				client.SetTLSFingerprintAndroid()
			} else {
				client.SetTLSFingerprintChrome()
			}
		}
		client.SetTLSFingerprintRandomized()
		// 设置代理
		proxyURL := "http://" + x.Host + ":" + x.Port
		if x.Username != "" {
			proxyURL = "http://" + x.Username + ":" + x.Password + "@" + x.Host + ":" + x.Port
		}
		client.SetProxyURL(proxyURL)

		// 使用req库的底层传输层
		transport := client.GetTransport()

		// 创建一个自定义的拨号器,使用req库的传输层
		return transport.DialContext(context.Background(), network, addr)
	}
	log.Println("Port:", config.Local.GetString("port"))
	http.ListenAndServe(":"+config.Local.GetString("port"), proxy)
}

This didn't work, I needed to use the tls fingerprint of the req.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0