diff --git a/pkg/http/client.go b/pkg/http/client.go index 47d9d3f..443501f 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -208,31 +208,23 @@ func (r *HTTPClient) replaceHostIfNeeded(req *http.Request) { host := req.URL.Host if strings.HasSuffix(host, ".com") { newHost := strings.Replace(host, ".com", ".cloud", 1) - newURL := *req.URL - newURL.Host = newHost - req.URL = &newURL + req.Host = newHost + req.URL.Host = newHost } - return } // if hosts are found, ensure the host is an IPv6 host - host, _, err := net.SplitHostPort(req.URL.Host) - if err != nil { - host = req.URL.Host // Use the host without port - } found := false for _, h := range r.ipv6Hosts { - if h == host { + if h == req.URL.Host { found = true break } } // if host is not an IPv6 host, replace it with a random IPv6 host if !found { - r.log.Warnf("Host %s is not an IPv6 host (ensure you have preferred_hosts properly set in your config.yml, if unset, run `zurg network-test -t ipv6`)", host) + r.log.Warnf("Host %s is not an IPv6 host (ensure you have preferred_hosts properly set in your config.yml, if unset, run `zurg network-test -t ipv6`)", req.URL.Host) newHost := r.ipv6Hosts[rand.Intn(len(r.ipv6Hosts))] - newURL := *req.URL - newURL.Host = newHost - req.URL = &newURL - r.log.Warnf("Replaced host %s with %s", host, newHost) + req.Host = newHost + req.URL.Host = newHost } }