Proxy requests 2
This commit is contained in:
@@ -14,13 +14,12 @@ import (
|
|||||||
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
||||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||||
"github.com/debridmediamanager.com/zurg/pkg/davextra"
|
"github.com/debridmediamanager.com/zurg/pkg/davextra"
|
||||||
"github.com/debridmediamanager.com/zurg/pkg/netutils"
|
|
||||||
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
|
||||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleGetRequest handles a GET request universally for both WebDAV and HTTP
|
// 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)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
isDav := true
|
isDav := true
|
||||||
if strings.Contains(requestPath, "/http") {
|
if strings.Contains(requestPath, "/http") {
|
||||||
@@ -90,11 +89,11 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cache.Add(requestPath, resp.Download)
|
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
|
resp, err := http.Get(url) // HTTP/2 is used by default if the server supports it
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error downloading file:", err)
|
log.Println("Error downloading file:", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user