Fix ipv6 stuffs 8

This commit is contained in:
Ben Sarmiento
2024-01-11 03:43:31 +01:00
parent c4fd7358b9
commit e9e4a7dfc2

View File

@@ -208,31 +208,23 @@ func (r *HTTPClient) replaceHostIfNeeded(req *http.Request) {
host := req.URL.Host host := req.URL.Host
if strings.HasSuffix(host, ".com") { if strings.HasSuffix(host, ".com") {
newHost := strings.Replace(host, ".com", ".cloud", 1) newHost := strings.Replace(host, ".com", ".cloud", 1)
newURL := *req.URL req.Host = newHost
newURL.Host = newHost req.URL.Host = newHost
req.URL = &newURL
} }
return
} }
// if hosts are found, ensure the host is an IPv6 host // 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 found := false
for _, h := range r.ipv6Hosts { for _, h := range r.ipv6Hosts {
if h == host { if h == req.URL.Host {
found = true found = true
break break
} }
} }
// if host is not an IPv6 host, replace it with a random IPv6 host // if host is not an IPv6 host, replace it with a random IPv6 host
if !found { 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))] newHost := r.ipv6Hosts[rand.Intn(len(r.ipv6Hosts))]
newURL := *req.URL req.Host = newHost
newURL.Host = newHost req.URL.Host = newHost
req.URL = &newURL
r.log.Warnf("Replaced host %s with %s", host, newHost)
} }
} }