Skip to content

Commit

Permalink
feat: add headers to REST options (#79)
Browse files Browse the repository at this point in the history
* headers option is added to REST options

* fixed linting

* fixed typing

* changed the order of header assignment
  • Loading branch information
nazmigorkem authored and TTtie committed Aug 10, 2023
1 parent d9b74cc commit 95114d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ declare namespace Dysnomia {
disableLatencyCompensation?: boolean;
domain?: string;
port?: string;
headers?: Record<string, number | string | string[]>;
https?: boolean;
latencyThreshold?: number;
ratelimiterOffset?: number;
Expand Down
1 change: 1 addition & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Client extends EventEmitter {
* @arg {Boolean} [options.rest.https=true] Whether to make requests to the Discord API over HTTPS (true) or HTTP (false)
* @arg {Number} [options.rest.latencyThreshold=30000] The average request latency at which Dysnomia will start emitting latency errors
* @arg {Number} [options.rest.port] The port to use for API requests. Defaults to 443 (HTTPS) or 80 (HTTP)
* @arg {Object} [options.rest.headers] Headers to be appended in REST requests
* @arg {Number} [options.rest.ratelimiterOffset=0] A number of milliseconds to offset the ratelimit timing calculations by
* @arg {Number} [options.rest.requestTimeout=15000] A number of milliseconds before REST requests are considered timed out
* @arg {Boolean} [options.restMode=false] Whether to enable getting objects over REST. Even with this option enabled, it is recommended that you check the cache first before using REST
Expand Down
3 changes: 3 additions & 0 deletions lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class RequestHandler {
let finalURL = url;

try {
if(this.options.headers) {
Object.assign(headers, this.options.headers);
}
if(auth) {
headers.Authorization = this._client._token;
}
Expand Down

0 comments on commit 95114d6

Please sign in to comment.