Handle preferred hosts in redirects too
This commit is contained in:
@@ -3,6 +3,7 @@ package universal
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -75,7 +76,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i
|
||||
|
||||
if url, exists := cache.Get(requestPath); exists {
|
||||
if c.ShouldServeFromRclone() {
|
||||
http.Redirect(w, r, url, http.StatusFound)
|
||||
redirect(w, r, url, c)
|
||||
} else {
|
||||
gf.streamFileToResponse(file, url, w, r, t, c, log)
|
||||
}
|
||||
@@ -112,7 +113,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i
|
||||
}
|
||||
cache.Add(requestPath, resp.Download)
|
||||
if c.ShouldServeFromRclone() {
|
||||
http.Redirect(w, r, resp.Download, http.StatusFound)
|
||||
redirect(w, r, resp.Download, c)
|
||||
} else {
|
||||
gf.streamFileToResponse(file, resp.Download, w, r, t, c, log)
|
||||
}
|
||||
@@ -174,8 +175,24 @@ func (gf *GetFile) playErrorVideo(link string, w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
if c.ShouldServeFromRclone() {
|
||||
http.Redirect(w, r, resp.Download, http.StatusFound)
|
||||
return
|
||||
redirect(w, r, resp.Download, c)
|
||||
}
|
||||
gf.streamFileToResponse(nil, resp.Download, w, r, t, c, log)
|
||||
}
|
||||
|
||||
func redirect(w http.ResponseWriter, r *http.Request, url string, c config.ConfigInterface) {
|
||||
prefHost := c.GetRandomPreferredHost()
|
||||
if prefHost != "" {
|
||||
url = replaceHostInURL(url, prefHost)
|
||||
}
|
||||
http.Redirect(w, r, url, http.StatusFound)
|
||||
}
|
||||
|
||||
func replaceHostInURL(inputURL string, newHost string) string {
|
||||
u, err := url.Parse(inputURL)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
u.Host = newHost
|
||||
return u.String()
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ type HTTPClient struct {
|
||||
func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
if r.config != nil && strings.Contains(req.Host, "download.real-debrid.") {
|
||||
prefHost := r.config.GetRandomPreferredHost()
|
||||
if host := prefHost; host != "" {
|
||||
req.Host = r.config.GetRandomPreferredHost()
|
||||
if prefHost != "" {
|
||||
req.Host = prefHost
|
||||
}
|
||||
}
|
||||
if r.BearerToken != "" {
|
||||
|
||||
Reference in New Issue
Block a user