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

feat(RequestManager): support setting global headers in options #70

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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