Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Rest): expose https.Agent options #6177

Merged
merged 5 commits into from Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rest/APIRequest.js
Expand Up @@ -6,7 +6,7 @@ const AbortController = require('abort-controller');
const fetch = require('node-fetch');
const { UserAgent } = require('../util/Constants');

const agent = new https.Agent({ keepAlive: true });
let agent = null;

class APIRequest {
constructor(rest, method, path, options) {
Expand All @@ -31,6 +31,10 @@ class APIRequest {
}

make() {
if (!agent) {
agent = new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
}
memikri marked this conversation as resolved.
Show resolved Hide resolved

const API =
this.options.versioned === false
? this.client.options.http.api
Expand Down
1 change: 1 addition & 0 deletions src/util/Options.js
Expand Up @@ -124,6 +124,7 @@ class Options extends null {
version: 9,
},
http: {
agent: {},
memikri marked this conversation as resolved.
Show resolved Hide resolved
version: 9,
api: 'https://discord.com/api',
cdn: 'https://cdn.discordapp.com',
Expand Down
2 changes: 2 additions & 0 deletions typings/index.d.ts
Expand Up @@ -34,6 +34,7 @@ import {
Snowflake,
} from 'discord-api-types/v9';
import { EventEmitter } from 'events';
import * as https from 'https';
memikri marked this conversation as resolved.
Show resolved Hide resolved
import { Stream } from 'stream';
import * as WebSocket from 'ws';
import {
Expand Down Expand Up @@ -3639,6 +3640,7 @@ export interface HTTPErrorData {
}

export interface HTTPOptions {
agent?: Omit<https.AgentOptions, 'keepAlive'>;
api?: string;
version?: number;
host?: string;
Expand Down