From e181af17c77ac3f2041a192bc59a86210a00e09e Mon Sep 17 00:00:00 2001 From: Pluto <68190554+Pluto-zZ-zZ@users.noreply.github.com> Date: Fri, 21 Jul 2023 15:55:22 +0800 Subject: [PATCH] fasthttpproxy support ipv6 (#1597) Co-authored-by: liwengang --- fasthttpproxy/http.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fasthttpproxy/http.go b/fasthttpproxy/http.go index 94d2b09c7e..c09bb2c195 100644 --- a/fasthttpproxy/http.go +++ b/fasthttpproxy/http.go @@ -42,11 +42,23 @@ func FasthttpHTTPDialerTimeout(proxy string, timeout time.Duration) fasthttp.Dia return func(addr string) (net.Conn, error) { var conn net.Conn var err error - if timeout == 0 { - conn, err = fasthttp.Dial(proxy) + + if strings.HasPrefix(proxy, "[") { + // ipv6 + if timeout == 0 { + conn, err = fasthttp.DialDualStack(proxy) + } else { + conn, err = fasthttp.DialDualStackTimeout(proxy, timeout) + } } else { - conn, err = fasthttp.DialTimeout(proxy, timeout) + // ipv4 + if timeout == 0 { + conn, err = fasthttp.Dial(proxy) + } else { + conn, err = fasthttp.DialTimeout(proxy, timeout) + } } + if err != nil { return nil, err }