Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(APIRequest): support setting global headers in HTTPOptions #5586

Merged
merged 2 commits into from May 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rest/APIRequest.js
Expand Up @@ -33,7 +33,7 @@ class APIRequest {
? this.client.options.http.api
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
const url = API + this.path;
let headers = {};
let headers = { ...this.client.options.http.headers };

if (this.options.auth !== false) headers.Authorization = this.rest.getAuth();
if (this.options.reason) headers['X-Audit-Log-Reason'] = encodeURIComponent(this.options.reason);
Expand Down
1 change: 1 addition & 0 deletions src/util/Constants.js
Expand Up @@ -80,6 +80,7 @@ exports.DefaultOptions = {
* @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN
* @property {string} [invite='https://discord.gg'] Base url of invites
* @property {string} [template='https://discord.new'] Base url of templates
* @property {Object} [headers] Additional headers to send for all API requests
*/
http: {
version: 8,
Expand Down
17 changes: 11 additions & 6 deletions typings/index.d.ts
Expand Up @@ -1378,7 +1378,7 @@ declare module 'discord.js' {
public eval<T>(fn: (client: Client) => T): Promise<T[]>;
public fetchClientValue(prop: string): Promise<any>;
public kill(): void;
public respawn(options?: { delay?: number, timeout?: number }): Promise<ChildProcess>;
public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
public send(message: any): Promise<Shard>;
public spawn(timeout?: number): Promise<ChildProcess>;

Expand Down Expand Up @@ -1411,7 +1411,7 @@ declare module 'discord.js' {
public broadcastEval<T>(fn: (client: Client) => T, shard: number): Promise<T>;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
public respawnAll(options?: { shardDelay?: number, respawnDelay?: number, timeout?: number }): Promise<void>;
public respawnAll(options?: { shardDelay?: number; respawnDelay?: number; timeout?: number }): Promise<void>;
public send(message: any): Promise<void>;

public static singleton(client: Client, mode: ShardingManagerMode): ShardClientUtil;
Expand Down Expand Up @@ -1448,11 +1448,15 @@ declare module 'discord.js' {
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
public respawnAll(options?: {
shardDelay?: number,
respawnDelay?: number,
timeout?: number,
shardDelay?: number;
respawnDelay?: number;
timeout?: number;
}): Promise<Collection<number, Shard>>;
public spawn(options?: {
amount?: number | 'auto';
delay?: number;
timeout?: number;
}): Promise<Collection<number, Shard>>;
public spawn(options?: { amount?: number | 'auto', delay?: number, timeout?: number }): Promise<Collection<number, Shard>>;

public on(event: 'shardCreate', listener: (shard: Shard) => void): this;

Expand Down Expand Up @@ -2810,6 +2814,7 @@ declare module 'discord.js' {
cdn?: string;
invite?: string;
template?: string;
headers?: Record<string, string>;
}

type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
Expand Down