From 4afa8da8ceb80a5aac70547e7410cc2615551bd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Cruz?= Date: Fri, 19 Jun 2020 16:42:01 +0100 Subject: [PATCH] Deal with URLs with literal IPv6 addresses (#645) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- prober/http.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/prober/http.go b/prober/http.go index 42552cb..7fa6c9c 100644 --- a/prober/http.go +++ b/prober/http.go @@ -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 { -- 2.25.1