Skip to content

FasthttpSocksDialer makes new proxy connection for each request #644

@ubombi

Description

@ubombi

SOCKS5 is capable of proxying multiple connections. I think there is no need to make a separate proxy connection for each HTTP(S) request.

func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
return func(addr string) (net.Conn, error) {
dialer, err := proxy.SOCKS5("tcp", proxyAddr, nil, proxy.Direct)
if err != nil {
return nil, err
}
return dialer.Dial("tcp", addr)
}
}

Should be replaced with code like:

func FasthttpSocksDialer(proxyAddr string) (fasthttp.DialFunc, error) {
	dialer, err := proxy.SOCKS5("tcp", proxyAddr, nil, proxy.Direct)
	if err != nil {
		return nil, err
	}
        return func(addr string) (net.Conn, error) {
		return dialer.Dial("tcp", addr)
	}, nil
}

Or replace it with Docs, like

// Example usage:
// Make a proxy dialer
//   dialer, err := proxy.SOCKS5("tcp", "localhost:9050", nil, proxy.Direct)
// And use it in Client
//   c := &fasthttp.Client{
//       Dial: func(addr string) (net.Conn, error) {
//           return dialer.Dial("tcp", addr)
//       },
//   }

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