diff options
author | Pluto <68190554+Pluto-zZ-zZ@users.noreply.github.com> | 2023-07-21 15:55:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-21 09:55:22 +0200 |
commit | e181af17c77ac3f2041a192bc59a86210a00e09e (patch) | |
tree | 69505d8e3eee14abf72b972762f7019f812d55f5 | |
parent | fix:fasthttp server with tlsConfig (#1595) (diff) | |
download | fasthttp-e181af17c77ac3f2041a192bc59a86210a00e09e.tar.gz fasthttp-e181af17c77ac3f2041a192bc59a86210a00e09e.tar.bz2 fasthttp-e181af17c77ac3f2041a192bc59a86210a00e09e.zip |
fasthttpproxy support ipv6 (#1597)
Co-authored-by: liwengang <liwengang.zz@bytedance.com>
-rw-r--r-- | fasthttpproxy/http.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/fasthttpproxy/http.go b/fasthttpproxy/http.go index 94d2b09..c09bb2c 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 } |