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() {
|
if cfg.ShouldForceIPv6() {
|
||||||
dialer := &net.Dialer{}
|
dialer := &net.Dialer{}
|
||||||
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
|
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)
|
host, port, err := net.SplitHostPort(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ipv6Address, ok := client.ipv6.Get(address); ok {
|
|
||||||
return dialer.DialContext(ctx, network, ipv6Address)
|
|
||||||
}
|
|
||||||
|
|
||||||
ips, err := net.DefaultResolver.LookupIPAddr(ctx, host)
|
ips, err := net.DefaultResolver.LookupIPAddr(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
if ip.IP.To4() == nil { // IPv6 address found
|
if ip.IP.To4() == nil { // IPv6 address found
|
||||||
ip6Host := ip.IP.String()
|
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)
|
return dialer.DialContext(ctx, network, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
DialContext: dialContext,
|
DialContext: dialContext,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user