Rename variables for easy reference

This commit is contained in:
Ben Adrian Sarmiento
2024-07-21 02:11:32 +02:00
parent 47751320f7
commit f8b9f8955b
8 changed files with 46 additions and 33 deletions

View File

@@ -201,6 +201,7 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
if !strings.Contains(req.Host, ".download.real-debrid.") {
return
}
// skip CDN servers
if req.Host[0] >= 'a' && req.Host[0] <= 'z' {
return
}
@@ -216,16 +217,18 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
} else if strings.HasSuffix(req.Host, ".cloud") {
newHost = strings.Replace(req.Host, ".cloud", ".com", 1)
}
// check if newHost is reachable
if r.CheckIfHostIsReachable(newHost) {
req.Host = newHost
req.URL.Host = req.Host
return
}
// just pick a random host
req.Host = r.hosts[rand.Intn(len(r.hosts))]
req.URL.Host = req.Host
}
// CheckIfHostIsReachable checks if the given host is passed in the list of reachable hosts
func (r *HTTPClient) CheckIfHostIsReachable(reqHost string) bool {
for _, host := range r.hosts {
if reqHost == host {