Skip to content

Commit e181af1

Browse files
Pluto-zZ-zZliwengang
and
liwengang
authoredJul 21, 2023
fasthttpproxy support ipv6 (#1597)
Co-authored-by: liwengang <liwengang.zz@bytedance.com>
1 parent 6eb2249 commit e181af1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎fasthttpproxy/http.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,23 @@ func FasthttpHTTPDialerTimeout(proxy string, timeout time.Duration) fasthttp.Dia
4242
return func(addr string) (net.Conn, error) {
4343
var conn net.Conn
4444
var err error
45-
if timeout == 0 {
46-
conn, err = fasthttp.Dial(proxy)
45+
46+
if strings.HasPrefix(proxy, "[") {
47+
// ipv6
48+
if timeout == 0 {
49+
conn, err = fasthttp.DialDualStack(proxy)
50+
} else {
51+
conn, err = fasthttp.DialDualStackTimeout(proxy, timeout)
52+
}
4753
} else {
48-
conn, err = fasthttp.DialTimeout(proxy, timeout)
54+
// ipv4
55+
if timeout == 0 {
56+
conn, err = fasthttp.Dial(proxy)
57+
} else {
58+
conn, err = fasthttp.DialTimeout(proxy, timeout)
59+
}
4960
}
61+
5062
if err != nil {
5163
return nil, err
5264
}

0 commit comments

Comments
 (0)
Please sign in to comment.