Skip to content

Commit 1143ae5

Browse files
committed
fix(download-size): get range request to fetch size
1 parent cd641ad commit 1143ae5

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/download/download-engine/streams/download-engine-fetch-stream/download-engine-fetch-stream-fetch.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class DownloadEngineFetchStreamFetch extends BaseDownloadEngineFe
2727
}
2828

2929
protected override async fetchWithoutRetryChunks(callback: WriteCallback) {
30-
const headers: { [key: string]: any } = {
30+
const headers: { [key: string]: any; } = {
3131
accept: "*/*",
3232
...this.options.headers
3333
};
@@ -105,13 +105,14 @@ export default class DownloadEngineFetchStreamFetch extends BaseDownloadEngineFe
105105
const fileName = parseContentDisposition(response.headers.get("content-disposition"));
106106

107107
let length = parseInt(response.headers.get("content-length")!) || 0;
108-
const contentEncoding = response.headers.get("content-encoding");
108+
const someLengthInfo = length;
109109

110+
const contentEncoding = response.headers.get("content-encoding");
110111
if (contentEncoding && contentEncoding !== "identity") {
111112
length = 0; // If content is encoded, we cannot determine the length reliably
112113
}
113114

114-
if (acceptRange && length === 0 && browserCheck() && MIN_LENGTH_FOR_MORE_INFO_REQUEST < length) {
115+
if (length === 0 && (acceptRange || browserCheck() && (method === "GET" || MIN_LENGTH_FOR_MORE_INFO_REQUEST < someLengthInfo))) {
115116
length = await this.fetchDownloadInfoWithoutRetryContentRange(url, method === "GET" ? response : undefined);
116117
}
117118

@@ -194,8 +195,8 @@ export default class DownloadEngineFetchStreamFetch extends BaseDownloadEngineFe
194195
}
195196

196197

197-
protected static convertHeadersToRecord(headers: Headers): { [key: string]: string } {
198-
const headerObj: { [key: string]: string } = {};
198+
protected static convertHeadersToRecord(headers: Headers): { [key: string]: string; } {
199+
const headerObj: { [key: string]: string; } = {};
199200
headers.forEach((value, key) => {
200201
headerObj[key] = value;
201202
});

src/download/download-engine/streams/download-engine-fetch-stream/download-engine-fetch-stream-xhr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ export default class DownloadEngineFetchStreamXhr extends BaseDownloadEngineFetc
215215
const contentEncoding = xhr.getResponseHeader("content-encoding");
216216

217217
let length = parseInt(xhr.getResponseHeader("content-length")!) || 0;
218+
const someLengthInfo = length;
219+
218220
if (contentEncoding && contentEncoding !== "identity") {
219221
length = 0; // If content is encoded, we cannot determine the length reliably
220222
}
221223

222-
if (acceptRange && length === 0 && MIN_LENGTH_FOR_MORE_INFO_REQUEST < length) {
224+
if (length === 0 && (acceptRange || method === "GET" || MIN_LENGTH_FOR_MORE_INFO_REQUEST < someLengthInfo)) {
223225
length = await this.fetchDownloadInfoWithoutRetryContentRange(url, method === "GET" ? xhr : undefined);
224226
}
225227

0 commit comments

Comments
 (0)