From 6c04ff003ed4ab28be743c2977f03b50fbec8eba Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Wed, 24 Nov 2021 18:36:29 +0100 Subject: [PATCH] support path in proxyURL (#628) * support path in proxyURL * linting * fix url * add debug print * remove debug print * include proxy port * add debug print * remove port, add protocol, fix pathname * fix path with trailing slash * cr fix --- src/components/Player.vue | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 1a678b0f..5c9b4ce0 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -230,8 +230,16 @@ export default { uri = lbry.url; if (this.getPreferenceBoolean("proxyLBRY", false)) { const url = new URL(uri); + const proxyURL = new URL(this.video.proxyUrl); + let proxyPath = proxyURL.pathname; + if (proxyPath.lastIndexOf("/") === proxyPath.length - 1) { + proxyPath = proxyPath.substring(0, proxyPath.length - 1); + } + url.searchParams.set("host", url.host); - url.host = new URL(this.video.proxyUrl).host; + url.protocol = proxyURL.protocol; + url.host = proxyURL.host; + url.pathname = proxyPath + url.pathname; uri = url.toString(); } const contentType = await fetch(uri, { @@ -251,7 +259,11 @@ export default { this.shaka.polyfill.installAll(); const localPlayer = new this.shaka.Player(videoEl); - const proxyHost = new URL(component.video.proxyUrl).host; + const proxyURL = new URL(component.video.proxyUrl); + let proxyPath = proxyURL.pathname; + if (proxyPath.lastIndexOf("/") === proxyPath.length - 1) { + proxyPath = proxyPath.substring(0, proxyPath.length - 1); + } localPlayer.getNetworkingEngine().registerRequestFilter((_type, request) => { const uri = request.uris[0]; @@ -263,10 +275,12 @@ export default { (component.getPreferenceBoolean("proxyLBRY", false) || headers.Range)) ) { url.searchParams.set("host", url.host); - url.host = proxyHost; + url.protocol = proxyURL.protocol; + url.host = proxyURL.host; + url.pathname = proxyPath + url.pathname; request.uris[0] = url.toString(); } - if (url.pathname === "/videoplayback") { + if (url.pathname === proxyPath + "/videoplayback") { if (headers.Range) { url.searchParams.set("range", headers.Range.split("=")[1]); request.headers = {};