diff --git a/fasthttpproxy/http.go b/fasthttpproxy/http.go index 80885d01e1..7ab1174f44 100644 --- a/fasthttpproxy/http.go +++ b/fasthttpproxy/http.go @@ -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 +} diff --git a/fasthttpproxy/socks5.go b/fasthttpproxy/socks5.go index 0328cd25cd..12c65e2b2a 100644 --- a/fasthttpproxy/socks5.go +++ b/fasthttpproxy/socks5.go @@ -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 +}