Sync latest from hotfix3
This commit is contained in:
@@ -24,7 +24,7 @@ type HTTPClient struct {
|
||||
getRetryIncr func(resp *http.Response, err error) int
|
||||
bearerToken string
|
||||
cfg config.ConfigInterface
|
||||
ipv6 cmap.ConcurrentMap[string, net.IP]
|
||||
ipv6 cmap.ConcurrentMap[string, string]
|
||||
log *zap.SugaredLogger
|
||||
}
|
||||
|
||||
@@ -60,26 +60,32 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
|
||||
return RATE_LIMIT_FACTOR // retry and increment attempt
|
||||
},
|
||||
cfg: cfg,
|
||||
ipv6: cmap.New[net.IP](),
|
||||
ipv6: cmap.New[string](),
|
||||
log: log,
|
||||
}
|
||||
|
||||
if cfg.ShouldForceIPv6() {
|
||||
dialer := &net.Dialer{}
|
||||
|
||||
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, address)
|
||||
host, port, _ := net.SplitHostPort(address)
|
||||
if ipv6Address, ok := client.ipv6.Get(address); ok {
|
||||
return dialer.DialContext(ctx, network, ipv6Address)
|
||||
}
|
||||
|
||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
if ip.IP.To4() == nil { // IPv6 address found
|
||||
ipv6Address := "[" + ip.IP.String() + "]"
|
||||
ip6Host := ip.IP.String()
|
||||
ipv6Address := net.JoinHostPort(ip6Host, port)
|
||||
client.ipv6.Set(address, ipv6Address)
|
||||
return dialer.DialContext(ctx, network, ipv6Address)
|
||||
}
|
||||
}
|
||||
return nil, net.UnknownNetworkError("no IPv6 address found")
|
||||
return dialer.DialContext(ctx, network, address)
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
|
||||
Reference in New Issue
Block a user