fix: proxy #1043
This commit is contained in:
parent
077f087ca0
commit
08f822e48a
@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('node:events');
|
||||
const http = require('node:http');
|
||||
const { setTimeout, setInterval, clearTimeout } = require('node:timers');
|
||||
const WebSocket = require('../../WebSocket');
|
||||
const { Status, Events, ShardEvents, Opcodes, WSEvents, WSCodes } = require('../../util/Constants');
|
||||
const Intents = require('../../util/Intents');
|
||||
const Util = require('../../util/Util');
|
||||
|
||||
const STATUS_KEYS = Object.keys(Status);
|
||||
const CONNECTION_STATE = Object.keys(WebSocket.WebSocket);
|
||||
@ -272,7 +272,7 @@ class WebSocketShard extends EventEmitter {
|
||||
Version : ${client.options.ws.version}
|
||||
Encoding : ${WebSocket.encoding}
|
||||
Compression: ${zlib ? 'zlib-stream' : 'none'}
|
||||
Agent : ${client.options.ws.agent instanceof http.Agent}`,
|
||||
Agent : ${Util.verifyProxyAgent(client.options.ws.agent)}`,
|
||||
);
|
||||
|
||||
this.status = this.status === Status.DISCONNECTED ? Status.RECONNECTING : Status.CONNECTING;
|
||||
@ -283,7 +283,7 @@ class WebSocketShard extends EventEmitter {
|
||||
// Adding a handshake timeout to just make sure no zombie connection appears.
|
||||
const ws = (this.connection = WebSocket.create(gateway, wsQuery, {
|
||||
handshakeTimeout: 30_000,
|
||||
agent: client.options.ws.agent instanceof http.Agent ? client.options.ws.agent : undefined,
|
||||
agent: Util.verifyProxyAgent(client.options.ws.agent) ? client.options.ws.agent : undefined,
|
||||
}));
|
||||
ws.onopen = this.onOpen.bind(this);
|
||||
ws.onmessage = this.onMessage.bind(this);
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const Buffer = require('node:buffer').Buffer;
|
||||
const http = require('node:http');
|
||||
const https = require('node:https');
|
||||
const { setTimeout } = require('node:timers');
|
||||
const makeFetchCookie = require('fetch-cookie');
|
||||
@ -9,6 +8,7 @@ const FormData = require('form-data');
|
||||
const fetchOriginal = require('node-fetch');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
const { ciphers } = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
const cookieJar = new CookieJar();
|
||||
const fetch = makeFetchCookie(fetchOriginal, cookieJar);
|
||||
@ -40,11 +40,17 @@ class APIRequest {
|
||||
|
||||
make(captchaKey, captchaRqToken) {
|
||||
if (!agent) {
|
||||
if (this.client.options.http.agent instanceof http.Agent) {
|
||||
this.client.options.http.agent.options.keepAlive = true;
|
||||
this.client.options.http.agent.options.honorCipherOrder = true;
|
||||
this.client.options.http.agent.options.minVersion = 'TLSv1.2';
|
||||
this.client.options.http.agent.options.ciphers = ciphers.join(':');
|
||||
if (Util.verifyProxyAgent(this.client.options.http.agent)) {
|
||||
// Bad code
|
||||
for (const [k, v] of Object.entries({
|
||||
keepAlive: true,
|
||||
honorCipherOrder: true,
|
||||
minVersion: 'TLSv1.2',
|
||||
ciphers: ciphers.join(':'),
|
||||
})) {
|
||||
this.client.options.http.agent.options[k] = v;
|
||||
this.client.options.http.agent.httpsAgent.options.options[k] = v;
|
||||
}
|
||||
agent = this.client.options.http.agent;
|
||||
} else {
|
||||
agent = new https.Agent({
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { Agent } = require('node:http');
|
||||
const { parse } = require('node:path');
|
||||
const process = require('node:process');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
@ -808,6 +809,15 @@ class Util extends null {
|
||||
let defaultValue;
|
||||
return () => (defaultValue ??= cb());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hacking check object instanceof Proxy-agent
|
||||
* @param {Object} object any
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static verifyProxyAgent(object) {
|
||||
return typeof object == 'object' && object.httpAgent instanceof Agent && object.httpsAgent instanceof Agent;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
Loading…
Reference in New Issue
Block a user