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
This commit is contained in:
Andrea Spacca 2021-11-24 18:36:29 +01:00 committed by GitHub
parent e1cffe418f
commit 6c04ff003e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 = {};