Skip to content

Commit

Permalink
Deal with URLs with literal IPv6 addresses (#645)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
edevil authored Jun 19, 2020
1 parent 1bc7680 commit 4afa8da
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4afa8da

Please sign in to comment.