Skip to content

Commit 07f671d

Browse files
committed
fix ipv6 unspecified address
1 parent a5a8577 commit 07f671d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Diff for: client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func safeAddr(ctx context.Context, resolver *net.Resolver, hostport string, opts
121121

122122
ip := net.ParseIP(host)
123123
if ip != nil {
124-
if ip.To4() != nil && c.isIPForbidden(ip) {
124+
if ip.IsUnspecified() || (ip.To4() != nil && c.isIPForbidden(ip)) {
125125
return "", fmt.Errorf("bad ip is detected: %v", ip)
126126
}
127127
return net.JoinHostPort(ip.String(), port), nil

Diff for: client_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func TestRequest(t *testing.T) {
1919
if _, err := DefaultClient.Get("http://192.168.0.1"); err == nil {
2020
t.Errorf("The request for localhost should be fail")
2121
}
22+
23+
if _, err := DefaultClient.Get("http://[::]"); err == nil {
24+
t.Errorf("The request for IPv6 unspecified address should be fail")
25+
}
2226
}
2327

2428
func TestIsHostForbidden(t *testing.T) {

0 commit comments

Comments
 (0)