Skip to content
Open
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
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ declare namespace Eris {
decodeReasons?: boolean;
disableLatencyCompensation?: boolean;
domain?: string;
https?: boolean;
latencyThreshold?: number;
port?: number;
ratelimiterOffset?: number;
requestTimeout?: number;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ class Client extends EventEmitter {
* @arg {Function} [options.reconnectDelay] A function which returns how long the bot should wait until reconnecting to Discord
* @arg {Number} [options.requestTimeout=15000] A number of milliseconds before requests are considered timed out. This option will stop affecting REST in a future release; that behavior is [DEPRECATED] and replaced by `options.rest.requestTimeout`
* @arg {Object} [options.rest] Options for the REST request handler
* @arg {Object} [options.rest.agent] A HTTPS Agent used to proxy requests
* @arg {Object} [options.rest.agent] A HTTP(S) Agent used to proxy requests
* @arg {String} [options.rest.baseURL] The base URL to use for API requests. Defaults to `/api/v${REST_VERSION}`
* @arg {Boolean} [options.rest.decodeReasons=true] [DEPRECATED] Whether reasons should be decoded with `decodeURIComponent()` when making REST requests. This is true by default to mirror pre-0.15.0 behavior (where reasons were expected to be URI-encoded), and should be set to false once your bot code stops. Reasons will no longer be decoded in the future
* @arg {Boolean} [options.rest.disableLatencyCompensation=false] Whether to disable the built-in latency compensator or not
* @arg {String} [options.rest.domain="discord.com"] The domain to use for API requests
* @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 Eris will start emitting latency errors
* @arg {Number} [options.rest.port] The port to use for API requests. This should only ever be used when proxying API 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
7 changes: 6 additions & 1 deletion lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DiscordHTTPError = require("../errors/DiscordHTTPError");
const DiscordRESTError = require("../errors/DiscordRESTError");
const Endpoints = require("./Endpoints");
const HTTPS = require("https");
const HTTP = require("http");
const MultipartData = require("../util/MultipartData");
const SequentialBucket = require("../util/SequentialBucket");
const Zlib = require("zlib");
Expand All @@ -27,6 +28,7 @@ class RequestHandler {
decodeReasons: true,
disableLatencyCompensation: false,
domain: "discord.com",
https: true,
latencyThreshold: client.options.latencyThreshold || 30000,
ratelimiterOffset: client.options.ratelimiterOffset || 0,
requestTimeout: client.options.requestTimeout || 15000,
Expand Down Expand Up @@ -160,9 +162,12 @@ class RequestHandler {

let req;
try {
req = HTTPS.request({
const requester = this.options.https ? HTTPS : HTTP;

req = requester.request({
method: method,
host: this.options.domain,
port: this.options.port,
path: this.options.baseURL + finalURL,
headers: headers,
agent: this.options.agent,
Expand Down