add agent support (#1973)

This commit is contained in:
Gus Caplan
2017-09-25 13:46:19 -05:00
committed by Crawl
parent 97dc85f491
commit 4d4d2f2db7
3 changed files with 8 additions and 2 deletions

View File

@@ -1,5 +1,8 @@
const querystring = require('querystring');
const snekfetch = require('snekfetch');
const https = require('https');
if (https.Agent) var agent = new https.Agent({ keepAlive: true });
class APIRequest {
constructor(rest, method, path, options) {
@@ -20,7 +23,7 @@ class APIRequest {
this.path += `?${queryString}`;
}
const request = snekfetch[this.method](`${API}${this.path}`);
const request = snekfetch[this.method](`${API}${this.path}`, { agent });
if (this.options.auth !== false) request.set('Authorization', this.rest.getAuth());
if (this.options.reason) request.set('X-Audit-Log-Reason', encodeURIComponent(this.options.reason));