Fix transport port

This commit is contained in:
Ben Sarmiento
2023-11-25 16:14:32 +01:00
parent 1b8f961d07
commit 0fdea17c91

View File

@@ -39,7 +39,7 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
dialer := &net.Dialer{} dialer := &net.Dialer{}
transport := &http.Transport{ transport := &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
host, _, err := net.SplitHostPort(addr) host, port, err := net.SplitHostPort(addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -57,13 +57,12 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
} }
} }
if ipv6 == nil { // No IPv6 address found, fallback to default if ipv6 == nil { // No IPv6 address found, fallback to default
r.log.Warnf("No IPv6 address found for %s, falling back to default", host) addr = net.JoinHostPort(host, port)
addr = net.JoinHostPort(host, req.URL.Port())
} else { } else {
addr = net.JoinHostPort(ipv6.String(), req.URL.Port()) addr = net.JoinHostPort(ipv6.String(), port)
} }
} else if ipv6 != nil && host == req.URL.Hostname() { } else if ipv6 != nil && host == req.URL.Hostname() {
addr = net.JoinHostPort(ipv6.String(), req.URL.Port()) addr = net.JoinHostPort(ipv6.String(), port)
} }
return dialer.DialContext(ctx, network, addr) return dialer.DialContext(ctx, network, addr)
}, },