fasthttpproxy support ipv6 (#1597)

Co-authored-by: liwengang <liwengang.zz@bytedance.com>
This commit is contained in:
Pluto
2023-07-21 15:55:22 +08:00
committed by GitHub
parent 6eb224954a
commit e181af17c7
+15 -3
View File
@@ -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
}