Skip to content

Commit

Permalink
fix(tryHeaders): do not mutate original object
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Aug 5, 2024
1 parent 29e50be commit e5bb8b6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export default class DownloadEngineBrowser<WriteStream extends BaseDownloadEngin
* Download file
*/
public static async createFromOptions(options: DownloadEngineOptionsBrowser) {
options = structuredClone(options);

DownloadEngineBrowser._validateOptions(options);
const partURLs = "partURLs" in options ? options.partURLs : [options.url];

Expand Down
2 changes: 0 additions & 2 deletions src/download/download-engine/engine/download-engine-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export default class DownloadEngineNodejs<T extends DownloadEngineWriteStreamNod
* By default, it will guess the strategy based on the URL
*/
public static async createFromOptions(options: DownloadEngineOptionsNodejs) {
options = structuredClone(options);

DownloadEngineNodejs._validateOptions(options);
const partURLs = "partURLs" in options ? options.partURLs : [options.url];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ export default abstract class BaseDownloadEngineFetchStream extends EventEmitter
public async fetchDownloadInfo(url: string): Promise<DownloadInfoResponse> {
let throwErr: Error | null = null;

const tryHeaders = "tryHeaders" in this.options && this.options.tryHeaders ? this.options.tryHeaders.slice() : [];

const fetchDownloadInfoCallback = async (): Promise<DownloadInfoResponse | null> => {
try {
return await this.fetchDownloadInfoWithoutRetry(url);
} catch (error: any) {
if (error instanceof HttpError && !this.retryOnServerError(error)) {
if ("tryHeaders" in this.options && this.options.tryHeaders?.length) {
this.options.headers = this.options.tryHeaders.shift();
if ("tryHeaders" in this.options && tryHeaders.length) {
this.options.headers = tryHeaders.shift();
await sleep(this.options.tryHeadersDelay ?? 0);
return await fetchDownloadInfoCallback();
}
Expand Down

0 comments on commit e5bb8b6

Please sign in to comment.