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