From 135abccd9c75c33c8510cdcbe33b0dea4198fe33 Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 10 May 2021 01:56:56 -0700 Subject: [PATCH] feat(APIRequest): support setting global headers in HTTPOptions (#5586) Co-authored-by: Vlad Frangu --- src/rest/APIRequest.js | 2 +- src/util/Constants.js | 1 + typings/index.d.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index d5e4ec183..c4487bf2a 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -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); diff --git a/src/util/Constants.js b/src/util/Constants.js index ca905ddc1..9d7aead77 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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, diff --git a/typings/index.d.ts b/typings/index.d.ts index 59ab672fc..9275049eb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2999,6 +2999,7 @@ declare module 'discord.js' { cdn?: string; invite?: string; template?: string; + headers?: Record; } type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;