feat(fasthttpproxy): add dual-stack connection support to enable IPv6 proxies for HTTP and SOCKS5 dialers (#1885)

* feat(fasthttpproxy): add dual-stack connection support to enable IPv6 proxies for HTTP and SOCKS5 dialers

- Added `FasthttpHTTPDialerDualStack` to support dual-stack (IPv4 and IPv6) connections for HTTP proxies, enabling IPv6 proxy usage.
- Added `FasthttpSocksDialerDualStack` to support dual-stack (IPv4 and IPv6) connections for SOCKS5 proxies, enabling IPv6 proxy usage.
- Improved dialer configuration to ensure compatibility with both IPv4 and IPv6 proxies.

* fix(lint): address linting issues in code
This commit is contained in:
Lavish
2024-10-22 22:49:00 +05:30
committed by GitHub
parent 56fd74b8c0
commit 40bdc4abc7
2 changed files with 44 additions and 0 deletions
+30
View File
@@ -33,3 +33,33 @@ func FasthttpHTTPDialerTimeout(proxy string, timeout time.Duration) fasthttp.Dia
dialFunc, _ := d.GetDialFunc(false)
return dialFunc
}
// FasthttpHTTPDialerDualStack returns a fasthttp.DialFunc that dials using
// the provided HTTP proxy with support for both IPv4 and IPv6.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpHTTPDialerDualStack("username:password@localhost:9050"),
// }
func FasthttpHTTPDialerDualStack(proxy string) fasthttp.DialFunc {
return FasthttpHTTPDialerDualStackTimeout(proxy, 0)
}
// FasthttpHTTPDialerDualStackTimeout returns a fasthttp.DialFunc that dials using
// the provided HTTP proxy with support for both IPv4 and IPv6, using the given timeout.
// The timeout parameter determines both the dial timeout and the CONNECT request timeout.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpHTTPDialerDualStackTimeout("username:password@localhost:9050", time.Second * 2),
// }
func FasthttpHTTPDialerDualStackTimeout(proxy string, timeout time.Duration) fasthttp.DialFunc {
d := Dialer{
Config: httpproxy.Config{HTTPProxy: proxy, HTTPSProxy: proxy}, Timeout: timeout, ConnectTimeout: timeout,
DialDualStack: true,
}
dialFunc, _ := d.GetDialFunc(false)
return dialFunc
}
+14
View File
@@ -18,3 +18,17 @@ func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
dialFunc, _ := d.GetDialFunc(false)
return dialFunc
}
// FasthttpSocksDialerDualStack returns a fasthttp.DialFunc that dials using
// the provided SOCKS5 proxy with support for both IPv4 and IPv6.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpSocksDialerDualStack("socks5://localhost:9050"),
// }
func FasthttpSocksDialerDualStack(proxyAddr string) fasthttp.DialFunc {
d := Dialer{Config: httpproxy.Config{HTTPProxy: proxyAddr, HTTPSProxy: proxyAddr}, DialDualStack: true}
dialFunc, _ := d.GetDialFunc(false)
return dialFunc
}