Skip to content

Commit

Permalink
feat(fasthttpproxy): add dual-stack connection support to enable IPv6…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
lavish440 authored Oct 22, 2024
1 parent 56fd74b commit 40bdc4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fasthttpproxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 14 additions & 0 deletions fasthttpproxy/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 40bdc4a

Please sign in to comment.