Skip to content

Commit 40bdc4a

Browse files
authored
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
1 parent 56fd74b commit 40bdc4a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

fasthttpproxy/http.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,33 @@ func FasthttpHTTPDialerTimeout(proxy string, timeout time.Duration) fasthttp.Dia
3333
dialFunc, _ := d.GetDialFunc(false)
3434
return dialFunc
3535
}
36+
37+
// FasthttpHTTPDialerDualStack returns a fasthttp.DialFunc that dials using
38+
// the provided HTTP proxy with support for both IPv4 and IPv6.
39+
//
40+
// Example usage:
41+
//
42+
// c := &fasthttp.Client{
43+
// Dial: fasthttpproxy.FasthttpHTTPDialerDualStack("username:password@localhost:9050"),
44+
// }
45+
func FasthttpHTTPDialerDualStack(proxy string) fasthttp.DialFunc {
46+
return FasthttpHTTPDialerDualStackTimeout(proxy, 0)
47+
}
48+
49+
// FasthttpHTTPDialerDualStackTimeout returns a fasthttp.DialFunc that dials using
50+
// the provided HTTP proxy with support for both IPv4 and IPv6, using the given timeout.
51+
// The timeout parameter determines both the dial timeout and the CONNECT request timeout.
52+
//
53+
// Example usage:
54+
//
55+
// c := &fasthttp.Client{
56+
// Dial: fasthttpproxy.FasthttpHTTPDialerDualStackTimeout("username:password@localhost:9050", time.Second * 2),
57+
// }
58+
func FasthttpHTTPDialerDualStackTimeout(proxy string, timeout time.Duration) fasthttp.DialFunc {
59+
d := Dialer{
60+
Config: httpproxy.Config{HTTPProxy: proxy, HTTPSProxy: proxy}, Timeout: timeout, ConnectTimeout: timeout,
61+
DialDualStack: true,
62+
}
63+
dialFunc, _ := d.GetDialFunc(false)
64+
return dialFunc
65+
}

fasthttpproxy/socks5.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
1818
dialFunc, _ := d.GetDialFunc(false)
1919
return dialFunc
2020
}
21+
22+
// FasthttpSocksDialerDualStack returns a fasthttp.DialFunc that dials using
23+
// the provided SOCKS5 proxy with support for both IPv4 and IPv6.
24+
//
25+
// Example usage:
26+
//
27+
// c := &fasthttp.Client{
28+
// Dial: fasthttpproxy.FasthttpSocksDialerDualStack("socks5://localhost:9050"),
29+
// }
30+
func FasthttpSocksDialerDualStack(proxyAddr string) fasthttp.DialFunc {
31+
d := Dialer{Config: httpproxy.Config{HTTPProxy: proxyAddr, HTTPSProxy: proxyAddr}, DialDualStack: true}
32+
dialFunc, _ := d.GetDialFunc(false)
33+
return dialFunc
34+
}

0 commit comments

Comments
 (0)