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
This commit is contained in:
Nils Maier 2019-09-06 21:55:27 +02:00
parent f04dda308b
commit ee7f470269

View File

@ -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) {