Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
feat(RequestManager): support setting global headers in options (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Advaith <advaithj1@gmail.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
3 people authored Oct 8, 2021
1 parent 65cb8e2 commit d1758c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/rest/src/lib/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface RESTOptions {
* @default 'https://cdn.discordapp.com'
*/
cdn: string;
/**
* Additional headers to send for all API requests
* @default {}
*/
headers: Record<string, string>;
/**
* The extra offset to add to rate limits in milliseconds
* @default 50
Expand Down
1 change: 1 addition & 0 deletions packages/rest/src/lib/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class RequestManager extends EventEmitter {

// Create the required headers
const headers: RequestHeaders = {
...this.options.headers,
'User-Agent': `${DefaultUserAgent} ${options.userAgentAppendix}`.trim(),
};

Expand Down
1 change: 1 addition & 0 deletions packages/rest/src/lib/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DefaultUserAgent = `DiscordBot (${Package.homepage}, ${Package.vers
export const DefaultRestOptions: Required<RESTOptions> = {
api: 'https://discord.com/api',
cdn: 'https://cdn.discordapp.com',
headers: {},
offset: 50,
retries: 3,
timeout: 15_000,
Expand Down

0 comments on commit d1758c7

Please sign in to comment.