mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
feat(Rest): expose https.Agent options (#6177)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ const FormData = require('@discordjs/form-data');
|
|||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { UserAgent } = require('../util/Constants');
|
const { UserAgent } = require('../util/Constants');
|
||||||
|
|
||||||
const agent = new https.Agent({ keepAlive: true });
|
let agent = null;
|
||||||
|
|
||||||
class APIRequest {
|
class APIRequest {
|
||||||
constructor(rest, method, path, options) {
|
constructor(rest, method, path, options) {
|
||||||
@@ -30,6 +30,8 @@ class APIRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
make() {
|
make() {
|
||||||
|
agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
|
||||||
|
|
||||||
const API =
|
const API =
|
||||||
this.options.versioned === false
|
this.options.versioned === false
|
||||||
? this.client.options.http.api
|
? this.client.options.http.api
|
||||||
|
|||||||
@@ -80,10 +80,18 @@
|
|||||||
* sent in the initial guild member list, must be between 50 and 250
|
* sent in the initial guild member list, must be between 50 and 250
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTPS Agent options.
|
||||||
|
* @typedef {Object} AgentOptions
|
||||||
|
* @see {@link https://nodejs.org/api/https.html#https_class_https_agent}
|
||||||
|
* @see {@link https://nodejs.org/api/http.html#http_new_agent_options}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP options
|
* HTTP options
|
||||||
* @typedef {Object} HTTPOptions
|
* @typedef {Object} HTTPOptions
|
||||||
* @property {number} [version=9] API version to use
|
* @property {number} [version=9] API version to use
|
||||||
|
* @property {AgentOptions} [agent={}] HTTPS Agent options
|
||||||
* @property {string} [api='https://discord.com/api'] Base url of the API
|
* @property {string} [api='https://discord.com/api'] Base url of the API
|
||||||
* @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN
|
* @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN
|
||||||
* @property {string} [invite='https://discord.gg'] Base url of invites
|
* @property {string} [invite='https://discord.gg'] Base url of invites
|
||||||
@@ -127,6 +135,7 @@ class Options extends null {
|
|||||||
version: 9,
|
version: 9,
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
agent: {},
|
||||||
version: 9,
|
version: 9,
|
||||||
api: 'https://discord.com/api',
|
api: 'https://discord.com/api',
|
||||||
cdn: 'https://cdn.discordapp.com',
|
cdn: 'https://cdn.discordapp.com',
|
||||||
|
|||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -47,6 +47,7 @@ import {
|
|||||||
Snowflake,
|
Snowflake,
|
||||||
} from 'discord-api-types/v9';
|
} from 'discord-api-types/v9';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
import { AgentOptions } from 'https';
|
||||||
import { Stream } from 'stream';
|
import { Stream } from 'stream';
|
||||||
import { MessagePort, Worker } from 'worker_threads';
|
import { MessagePort, Worker } from 'worker_threads';
|
||||||
import * as WebSocket from 'ws';
|
import * as WebSocket from 'ws';
|
||||||
@@ -3893,6 +3894,7 @@ export interface HTTPErrorData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface HTTPOptions {
|
export interface HTTPOptions {
|
||||||
|
agent?: Omit<AgentOptions, 'keepAlive'>;
|
||||||
api?: string;
|
api?: string;
|
||||||
version?: number;
|
version?: number;
|
||||||
host?: string;
|
host?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user