Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 7f1c9be

Browse files
ckohenmemikrikyranet
authored
feat: expose https agent options (#82)
Co-authored-by: Shino <shinotheshino@gmail.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com>
1 parent 6df603e commit 7f1c9be

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/rest/src/lib/REST.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { EventEmitter } from 'node:events';
22
import { CDN } from './CDN';
33
import { InternalRequest, RequestData, RequestManager, RequestMethod, RouteLike } from './RequestManager';
44
import { DefaultRestOptions, RESTEvents } from './utils/constants';
5+
import type { AgentOptions } from 'node:https';
56

67
/**
78
* Options to be passed when creating the REST instance
89
*/
910
export interface RESTOptions {
11+
/**
12+
* HTTPS Agent options
13+
* @default {}
14+
*/
15+
agent: Omit<AgentOptions, 'keepAlive'>;
1016
/**
1117
* The base api path, without version
1218
* @default 'https://discord.com/api'

packages/rest/src/lib/RequestManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SequentialHandler } from './handlers/SequentialHandler';
99
import type { RESTOptions } from './REST';
1010
import { DefaultRestOptions, DefaultUserAgent } from './utils/constants';
1111

12-
const agent = new Agent({ keepAlive: true });
12+
let agent: Agent | null = null;
1313

1414
/**
1515
* Represents an attachment to be added to the request
@@ -198,6 +198,8 @@ export class RequestManager extends EventEmitter {
198198
private resolveRequest(request: InternalRequest): { url: string; fetchOptions: RequestInit } {
199199
const { options } = this;
200200

201+
agent ??= new Agent({ ...options.agent, keepAlive: true });
202+
201203
let query = '';
202204

203205
// If a query option is passed, use it

packages/rest/src/lib/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Package = require('../../../package.json');
77
export const DefaultUserAgent = `DiscordBot (${Package.homepage}, ${Package.version})`;
88

99
export const DefaultRestOptions: Required<RESTOptions> = {
10+
agent: {},
1011
api: 'https://discord.com/api',
1112
cdn: 'https://cdn.discordapp.com',
1213
headers: {},

0 commit comments

Comments
 (0)