WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 71dad8b

Browse files
committed
first ip or nil IP was used for connection
1 parent 379260d commit 71dad8b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

http_client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ func publicUnicastOnlyDialContext(ctx context.Context, network, addr string) (ne
4949
}
5050
}
5151

52+
var dialErrs []error
5253
connectTimeout := requestTimeoutSecs * time.Second / time.Duration(len(ipAddrs)+1)
5354
for _, ipAddr := range ipAddrs {
55+
ip = net.ParseIP(ipAddr)
5456
switch {
5557
case allowLoopback && ip.IsLoopback():
5658
case !ip.IsGlobalUnicast() || ip.IsPrivate():
59+
dialErrs = append(dialErrs, fmt.Errorf("forbidden address: %s", ipAddr))
5760
continue
5861
}
5962

@@ -63,7 +66,8 @@ func publicUnicastOnlyDialContext(ctx context.Context, network, addr string) (ne
6366
if nil == err {
6467
return conn, nil
6568
}
69+
dialErrs = append(dialErrs, fmt.Errorf("failed to dial '%s:%s': %w", ipAddr, port, err))
6670
}
6771

68-
return nil, fmt.Errorf("failed to dial port %q on any address in %q", port, ipAddrs)
72+
return nil, fmt.Errorf("failed to dial: %q", dialErrs)
6973
}

0 commit comments

Comments
 (0)