Ensure we have reachable hosts

This commit is contained in:
Ben Adrian Sarmiento
2024-08-28 01:10:09 +02:00
parent bac6351071
commit f04a0ff42c

View File

@@ -203,6 +203,9 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
// ensureReachableDownloadServer ensures that the request is sent to a reachable host
// if not, it will replace the host with a reachable one
func (r *HTTPClient) ensureReachableDownloadServer(req *http.Request) {
if len(r.hosts) == 0 {
return
}
// skip if not a download server
if !strings.Contains(req.Host, ".download.real-debrid.") {
return
@@ -264,7 +267,7 @@ func (r *HTTPClient) shouldRetry(req *http.Request, resp *http.Response, err err
}
// retry on timeout errors for download requests
if err != nil && strings.Contains(err.Error(), "timeout") && strings.Contains(req.Host, ".download.real-debrid.") {
if err != nil && strings.Contains(err.Error(), "timeout") && strings.Contains(req.Host, ".download.real-debrid.") && len(r.hosts) > 1 {
oldHost := req.Host
// remove old host from the list of reachable hosts
for i, host := range r.hosts {