Deal with URLs with literal IPv6 addresses (#645)
authorAndré Cruz <acruz@cloudflare.com>
Fri, 19 Jun 2020 15:42:01 +0000 (16:42 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Jun 2020 15:42:01 +0000 (16:42 +0100)
Recent versions of Go have started enforcing the usage of
brackets in URLs with literal IPv6 addresses. This change
prevents the attempt to resolve an address in the form
[address]. URL.Hostname() takes care of striping the brackets.

Signed-off-by: André Cruz <acruz@cloudflare.com>
prober/http.go

index 42552cbb0561ff680bc525ed3d7aa22b330ac78f..7fa6c9c1a4e04daf53c7813f05a331131039e955 100644 (file)
@@ -314,11 +314,9 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
                level.Error(logger).Log("msg", "Could not parse target URL", "err", err)
                return false
        }
-       targetHost, targetPort, err := net.SplitHostPort(targetURL.Host)
-       // If split fails, assuming it's a hostname without port part.
-       if err != nil {
-               targetHost = targetURL.Host
-       }
+
+       targetHost := targetURL.Hostname()
+       targetPort := targetURL.Port()
 
        ip, lookupTime, err := chooseProtocol(ctx, module.HTTP.IPProtocol, module.HTTP.IPProtocolFallback, targetHost, registry, logger)
        if err != nil {