Fix location of pref hosts injection

This commit is contained in:
Ben Sarmiento
2024-01-07 16:17:31 +01:00
parent 120df54f35
commit 769c4a6803
3 changed files with 22 additions and 21 deletions

View File

@@ -3,7 +3,6 @@ package universal
import (
"io"
"net/http"
"net/url"
"path/filepath"
"strings"
@@ -151,18 +150,5 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
}
func redirect(resp http.ResponseWriter, req *http.Request, url string, cfg config.ConfigInterface) {
prefHost := cfg.GetRandomPreferredHost()
if prefHost != "" {
url = replaceHostInURL(url, prefHost)
}
http.Redirect(resp, req, 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()
}