Skip to content

Commit

Permalink
feat: allow passing in user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Aug 13, 2023
1 parent 60bba59 commit eb847b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/fragmenter-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class FragmenterContext extends (EventEmitter as new () => TypedEventEmit
useConsoleLog: true,
forceCacheBust: false,
logTrace: false,
userAgent: undefined,
...options,
};

Expand Down
4 changes: 4 additions & 0 deletions src/install/stream-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class StreamDownloader extends (EventEmitter as new () => TypedEventEmitt
private async getReadStream(startIndex: number, url: string): Promise<AxiosResponse<stream.Readable>> {
const headers: AxiosRequestHeaders = {};

if (this.ctx.options.userAgent !== undefined) {
headers['User-Agent'] = this.ctx.options.userAgent;
}

if (startIndex !== 0) {
headers.Range = `bytes=${startIndex}-`;
}
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ export interface BaseCommandOptions {
* Defaults to `false`,
*/
logTrace: boolean,

/**
* The user agent to use for HTTP requests.
*
* Defaults to the Axios user agent.
*/
userAgent?: string,
}

export type PackOptions = Partial<BaseCommandOptions> & {
Expand Down

0 comments on commit eb847b2

Please sign in to comment.