diff --git a/internal/proxy/media_proxy.go b/internal/proxy/media_proxy.go index 14de7d7e..8f6856d6 100644 --- a/internal/proxy/media_proxy.go +++ b/internal/proxy/media_proxy.go @@ -61,6 +61,14 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, } }) + doc.Find("video").Each(func(i int, video *goquery.Selection) { + if posterAttrValue, ok := video.Attr("poster"); ok { + if !isDataURL(posterAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(posterAttrValue)) { + video.SetAttr("poster", proxifyFunction(router, posterAttrValue)) + } + } + }) + case "audio": doc.Find("audio").Each(func(i int, audio *goquery.Selection) { if srcAttrValue, ok := audio.Attr("src"); ok { @@ -85,6 +93,12 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, video.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } + + if posterAttrValue, ok := video.Attr("poster"); ok { + if !isDataURL(posterAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(posterAttrValue)) { + video.SetAttr("poster", proxifyFunction(router, posterAttrValue)) + } + } }) doc.Find("video source").Each(func(i int, sourceElement *goquery.Selection) { diff --git a/internal/proxy/media_proxy_test.go b/internal/proxy/media_proxy_test.go index 76499231..bd0de097 100644 --- a/internal/proxy/media_proxy_test.go +++ b/internal/proxy/media_proxy_test.go @@ -377,3 +377,53 @@ func TestProxyWithImageSourceDataURL(t *testing.T) { t.Errorf(`Not expected output: got %s`, output) } } + +func TestProxyFilterWithVideo(t *testing.T) { + os.Clearenv() + os.Setenv("PROXY_OPTION", "all") + os.Setenv("PROXY_MEDIA_TYPES", "video") + os.Setenv("PROXY_PRIVATE_KEY", "test") + + var err error + parser := config.NewParser() + config.Opts, err = parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + r := mux.NewRouter() + r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy") + + input := `` + expected := `` + output := ProxyRewriter(r, input) + + if expected != output { + t.Errorf(`Not expected output: got %s`, output) + } +} + +func TestProxyFilterVideoPoster(t *testing.T) { + os.Clearenv() + os.Setenv("PROXY_OPTION", "all") + os.Setenv("PROXY_MEDIA_TYPES", "image") + os.Setenv("PROXY_PRIVATE_KEY", "test") + + var err error + parser := config.NewParser() + config.Opts, err = parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + r := mux.NewRouter() + r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy") + + input := `` + expected := `` + output := ProxyRewriter(r, input) + + if expected != output { + t.Errorf(`Not expected output: got %s`, output) + } +}