Do no replace with random host if not on reachable host list
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -200,7 +199,10 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
|||||||
return resp, err
|
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) {
|
func (r *HTTPClient) ensureReachableHost(req *http.Request) {
|
||||||
|
// skip if not a download server
|
||||||
if !strings.Contains(req.Host, ".download.real-debrid.") {
|
if !strings.Contains(req.Host, ".download.real-debrid.") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -208,7 +210,6 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
|
|||||||
if req.Host[0] >= 'a' && req.Host[0] <= 'z' {
|
if req.Host[0] >= 'a' && req.Host[0] <= 'z' {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if req.Host is in r.hosts
|
// check if req.Host is in r.hosts
|
||||||
if r.CheckIfHostIsReachable(req.Host) {
|
if r.CheckIfHostIsReachable(req.Host) {
|
||||||
return
|
return
|
||||||
@@ -226,9 +227,13 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
|
|||||||
req.URL.Host = req.Host
|
req.URL.Host = req.Host
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// just pick a random host
|
|
||||||
req.Host = r.hosts[rand.Intn(len(r.hosts))]
|
// // just pick a random host
|
||||||
req.URL.Host = req.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
|
// CheckIfHostIsReachable checks if the given host is passed in the list of reachable hosts
|
||||||
|
|||||||
Reference in New Issue
Block a user