From ee7f4702694042d91c00f0d37a0547ba3e4af2a8 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Fri, 6 Sep 2019 21:55:27 +0200 Subject: [PATCH] Use ranges in preroll to avoid large downloads This will effectively request the first 2 bytes from a server? Why 2 bytes? Because a lot of servers are broken when bytes=0-0 Related to #70 --- lib/manager/download.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/manager/download.ts b/lib/manager/download.ts index 8557525..0b72b60 100644 --- a/lib/manager/download.ts +++ b/lib/manager/download.ts @@ -260,6 +260,9 @@ export class Download extends BaseDownload { const {signal} = controller; const res = await fetch(this.uURL.toString(), { method: "GET", + headers: new Headers({ + Range: "bytes=0-1", + }), mode: "same-origin", signal, }); @@ -305,6 +308,9 @@ export class Download extends BaseDownload { const {signal} = controller; const res = await fetch(rurl, { method: "GET", + headers: new Headers({ + Range: "bytes=0-1", + }), signal, }); if (res.body) { @@ -346,7 +352,7 @@ export class Download extends BaseDownload { this.cancel(); this.error = "SERVER_UNAUTHORIZED"; } - else if (status === 400 || status === 405) { + else if (status === 400 || status === 405 || status === 416) { PREROLL_NOPE.add(this.uURL.host); } else if (status > 400 && status < 500) {