From dcb87b225af3258abfc9d52126150b798fa9b1ca Mon Sep 17 00:00:00 2001 From: Fijxu Date: Thu, 24 Apr 2025 18:42:10 -0400 Subject: [PATCH] fix: Fix content-range header in video proxy for partial requests from: https://github.com/iv-org/invidious-companion/pull/101 --- internal/paths/videoplayback.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/paths/videoplayback.go b/internal/paths/videoplayback.go index 92a7031..fb4e9e4 100644 --- a/internal/paths/videoplayback.go +++ b/internal/paths/videoplayback.go @@ -184,7 +184,14 @@ func Videoplayback(w http.ResponseWriter, req *http.Request) { byteParts := strings.Split(requestBytes, "-") firstByte, lastByte := byteParts[0], byteParts[1] if lastByte != "" { - w.Header().Add("content-range", "bytes "+requestBytes+"/*") + clen := q.Get("clen") + + if clen == "" { + w.Header().Add("content-range", "bytes "+requestBytes+"/*") + } else { + w.Header().Add("content-range", "bytes "+requestBytes+"/"+clen) + } + w.WriteHeader(206) } else { // i.e. "bytes=0-", "bytes=600-" @@ -205,8 +212,6 @@ func Videoplayback(w http.ResponseWriter, req *http.Request) { } } - // w.WriteHeader(resp.StatusCode) - if req.Method == "GET" && (resp.Header.Get("Content-Type") == "application/x-mpegurl" || resp.Header.Get("Content-Type") == "application/vnd.apple.mpegurl") { bytes, err := io.ReadAll(resp.Body) if err != nil {