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{}
transport := &http.Transport{
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 {
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
r.log.Warnf("No IPv6 address found for %s, falling back to default", host)
addr = net.JoinHostPort(host, req.URL.Port())
addr = net.JoinHostPort(host, port)
} else {
addr = net.JoinHostPort(ipv6.String(), req.URL.Port())
addr = net.JoinHostPort(ipv6.String(), port)
}
} 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)
},