gologin 2.1.26 → 2.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/gologin.js +11 -3
- package/src/utils/http.js +17 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/gologin.js
CHANGED
|
@@ -80,6 +80,8 @@ export class GoLogin {
|
|
|
80
80
|
this.processKillTimeout = 1 * 1000;
|
|
81
81
|
this.browserMajorVersion = 0;
|
|
82
82
|
this.newProxyOrbbitaMajorVersion = 135;
|
|
83
|
+
this.proxyCheckTimeout = options.proxyCheckTimeout || 13 * 1000;
|
|
84
|
+
this.proxyCheckAttempts = options.proxyCheckAttempts || 3;
|
|
83
85
|
|
|
84
86
|
if (process.env.DISABLE_TELEMETRY !== 'true') {
|
|
85
87
|
Sentry.init({
|
|
@@ -738,9 +740,15 @@ export class GoLogin {
|
|
|
738
740
|
|
|
739
741
|
const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
|
|
740
742
|
debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
|
|
741
|
-
|
|
743
|
+
|
|
744
|
+
data = await makeRequest(TIMEZONE_URL, {
|
|
745
|
+
proxy: proxyUrl,
|
|
746
|
+
timeout: this.proxyCheckTimeout,
|
|
747
|
+
maxAttempts: this.proxyCheckAttempts,
|
|
748
|
+
method: 'GET',
|
|
749
|
+
});
|
|
742
750
|
} else {
|
|
743
|
-
data = await makeRequest(TIMEZONE_URL, { timeout:
|
|
751
|
+
data = await makeRequest(TIMEZONE_URL, { timeout: this.proxyCheckTimeout, maxAttempts: this.proxyCheckAttempts, method: 'GET' });
|
|
744
752
|
}
|
|
745
753
|
|
|
746
754
|
debug('getTimeZone finish', data);
|
|
@@ -810,7 +818,7 @@ export class GoLogin {
|
|
|
810
818
|
|
|
811
819
|
await makeRequest(
|
|
812
820
|
`${API_URL}/proxy/set_proxy_statuses`,
|
|
813
|
-
{ timeout:
|
|
821
|
+
{ timeout: this.proxyCheckTimeout, maxAttempts: this.proxyCheckAttempts, method: 'POST', json: statusBody },
|
|
814
822
|
{ token: this.access_token, fallbackUrl: `${FALLBACK_API_URL}/proxy/set_proxy_statuses` },
|
|
815
823
|
).catch();
|
|
816
824
|
}
|
package/src/utils/http.js
CHANGED
|
@@ -3,8 +3,23 @@ import requests from 'requestretry';
|
|
|
3
3
|
|
|
4
4
|
const TIMEZONE_URL = 'https://geo.myip.link';
|
|
5
5
|
|
|
6
|
+
const createTimeoutPromise = (timeoutMs) => new Promise((_, reject) => {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
reject(new Error(`Request timeout after ${timeoutMs}ms`));
|
|
9
|
+
}, timeoutMs);
|
|
10
|
+
});
|
|
11
|
+
|
|
6
12
|
const attemptRequest = async (requestUrl, options) => {
|
|
7
|
-
const
|
|
13
|
+
const requestPromise = requests(requestUrl, options);
|
|
14
|
+
|
|
15
|
+
let req;
|
|
16
|
+
if (options.proxy) {
|
|
17
|
+
const timeoutPromise = createTimeoutPromise(options.timeout || 30000);
|
|
18
|
+
req = await Promise.race([requestPromise, timeoutPromise]);
|
|
19
|
+
} else {
|
|
20
|
+
req = await requestPromise;
|
|
21
|
+
}
|
|
22
|
+
|
|
8
23
|
if (req.statusCode >= 400) {
|
|
9
24
|
const error = new Error(req.body);
|
|
10
25
|
error.statusCode = req.statusCode;
|
|
@@ -39,7 +54,7 @@ export const makeRequest = async (url, options, internalOptions) => {
|
|
|
39
54
|
};
|
|
40
55
|
|
|
41
56
|
export const checkSocksProxy = async (agent) => new Promise((resolve, reject) => {
|
|
42
|
-
_get(TIMEZONE_URL, { agent, timeout:
|
|
57
|
+
_get(TIMEZONE_URL, { agent, timeout: 8000 }, (res) => {
|
|
43
58
|
let resultResponse = '';
|
|
44
59
|
res.on('data', (data) => {
|
|
45
60
|
resultResponse += data;
|