From f5cbf150ef9b00c2b40a4df3b197513f2aa5803a Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Wed, 21 Aug 2024 23:27:22 +0200 Subject: [PATCH] Do no replace with random host if not on reachable host list --- pkg/http/client.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/http/client.go b/pkg/http/client.go index e38e3c6..ee4b68a 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "math" - "math/rand" "net" "net/http" "net/url" @@ -200,7 +199,10 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) { return resp, err } +// ensureReachableHost ensures that the request is sent to a reachable host +// if not, it will replace the host with a reachable one func (r *HTTPClient) ensureReachableHost(req *http.Request) { + // skip if not a download server if !strings.Contains(req.Host, ".download.real-debrid.") { return } @@ -208,7 +210,6 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) { if req.Host[0] >= 'a' && req.Host[0] <= 'z' { return } - // check if req.Host is in r.hosts if r.CheckIfHostIsReachable(req.Host) { return @@ -226,9 +227,13 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) { 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 + + // // just pick a random host + // req.Host = r.hosts[rand.Intn(len(r.hosts))] + // req.URL.Host = req.Host + + // just retain the original host if not in the list of reachable hosts + r.log.Debugf("Host %s is not found on the list of reachable hosts", req.Host) } // CheckIfHostIsReachable checks if the given host is passed in the list of reachable hosts