Skip to content

Commit

Permalink
fasthttpproxy support ipv6 (#1597)
Browse files Browse the repository at this point in the history
Co-authored-by: liwengang <liwengang.zz@bytedance.com>
  • Loading branch information
Pluto-zZ-zZ and liwengang authored Jul 21, 2023
1 parent 6eb2249 commit e181af1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions fasthttpproxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e181af1

Please sign in to comment.