Proxy requests 2

This commit is contained in:
Ben Sarmiento
2023-10-28 06:18:47 +02:00
parent 96b85c8f79
commit a9d017f481

View File

@@ -14,13 +14,12 @@ import (
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/davextra"
"github.com/debridmediamanager.com/zurg/pkg/netutils"
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
"github.com/hashicorp/golang-lru/v2/expirable"
)
// HandleGetRequest handles a GET request universally for both WebDAV and HTTP
func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string], master *netutils.NetMaster) {
func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
requestPath := path.Clean(r.URL.Path)
isDav := true
if strings.Contains(requestPath, "/http") {
@@ -90,11 +89,11 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
}
} else {
cache.Add(requestPath, resp.Download)
streamFileToResponse(resp.Download, w, master)
streamFileToResponse(resp.Download, w)
}
}
func streamFileToResponse(url string, w http.ResponseWriter, master *netutils.NetMaster) {
func streamFileToResponse(url string, w http.ResponseWriter) {
resp, err := http.Get(url) // HTTP/2 is used by default if the server supports it
if err != nil {
log.Println("Error downloading file:", err)