Skip to content

Commit

Permalink
fix(options): remove http(s) agent
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Apr 5, 2022
1 parent 405b6f0 commit d9dd20e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
6 changes: 0 additions & 6 deletions packages/rest/src/lib/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
RouteLike,
} from './RequestManager';
import { DefaultRestOptions, RESTEvents } from './utils/constants';
import type { AgentOptions } from 'node:https';
import type { RequestInit, Response } from 'undici';
import type { HashData } from './RequestManager';
import type Collection from '@discordjs/collection';
Expand All @@ -19,11 +18,6 @@ import type { IHandler } from './handlers/IHandler';
* Options to be passed when creating the REST instance
*/
export interface RESTOptions {
/**
* HTTPS Agent options
* @default {}
*/
agent: Omit<AgentOptions, 'keepAlive'>;
/**
* The base api path, without version
* @default 'https://discord.com/api'
Expand Down
11 changes: 2 additions & 9 deletions packages/rest/src/lib/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Collection from '@discordjs/collection';
import { DiscordSnowflake } from '@sapphire/snowflake';
import { Blob } from 'node:buffer';
import { EventEmitter } from 'node:events';
import { Agent as httpsAgent } from 'node:https';
import { Agent as httpAgent } from 'node:http';
import { FormData, type RequestInit, type BodyInit } from 'undici';
import type { IHandler } from './handlers/IHandler';
import { SequentialHandler } from './handlers/SequentialHandler';
Expand Down Expand Up @@ -187,7 +185,6 @@ export class RequestManager extends EventEmitter {

private hashTimer!: NodeJS.Timer;
private handlerTimer!: NodeJS.Timer;
private agent: httpsAgent | httpAgent | null = null;

public readonly options: RESTOptions;

Expand Down Expand Up @@ -324,10 +321,6 @@ export class RequestManager extends EventEmitter {
private resolveRequest(request: InternalRequest): { url: string; fetchOptions: RequestInit } {
const { options } = this;

this.agent ??= options.api.startsWith('https')
? new httpsAgent({ ...options.agent, keepAlive: true })
: new httpAgent({ ...options.agent, keepAlive: true });

let query = '';

// If a query option is passed, use it
Expand Down Expand Up @@ -413,8 +406,8 @@ export class RequestManager extends EventEmitter {
}
}

const fetchOptions = {
agent: this.agent,
const fetchOptions: RequestInit = {
body: finalBody!,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
headers: { ...(request.headers ?? {}), ...additionalHeaders, ...headers } as Record<string, string>,
method: request.method,
Expand Down
1 change: 0 additions & 1 deletion packages/rest/src/lib/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Package = require('../../../package.json');
export const DefaultUserAgent = `DiscordBot (${Package.homepage}, ${Package.version})`;

export const DefaultRestOptions: Required<RESTOptions> = {
agent: {},
api: 'https://discord.com/api',
cdn: 'https://cdn.discordapp.com',
headers: {},
Expand Down

0 comments on commit d9dd20e

Please sign in to comment.