Reorder logic
This commit is contained in:
@@ -108,19 +108,17 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
|
||||
if cfg.ShouldForceIPv6() {
|
||||
dialer := &net.Dialer{}
|
||||
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
if ipv6Address, ok := client.ipv6.Get(address); ok {
|
||||
return dialer.DialContext(ctx, network, ipv6Address)
|
||||
}
|
||||
host, port, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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
|
||||
ip6Host := ip.IP.String()
|
||||
@@ -131,7 +129,6 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
|
||||
}
|
||||
return dialer.DialContext(ctx, network, address)
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
DialContext: dialContext,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user