curl-wrap 2.0.0 → 2.0.1
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/index.js +14 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,12 +2,6 @@ const {spawn, spawnSync} = require('child_process');
|
|
|
2
2
|
const fs = require('fs/promises');
|
|
3
3
|
const {CookieJar} = require('tough-cookie');
|
|
4
4
|
|
|
5
|
-
function getDefaultProxyPort(proxyType) {
|
|
6
|
-
if (proxyType === 'http') return 80;
|
|
7
|
-
if (proxyType === 'https') return 443;
|
|
8
|
-
return 1080;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
/**
|
|
12
6
|
* Returns proxy url based on the proxy options.
|
|
13
7
|
*
|
|
@@ -27,15 +21,23 @@ function makeProxyUrl(proxy, options) {
|
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
const auth = proxy.auth || options.auth || {};
|
|
30
|
-
const uri = new URL(
|
|
24
|
+
const uri = new URL(address);
|
|
31
25
|
if (!uri.port) {
|
|
32
|
-
|
|
26
|
+
const port = proxy.port || options.port;
|
|
27
|
+
if (port) {
|
|
28
|
+
uri.port = port;
|
|
29
|
+
}
|
|
30
|
+
else if (uri.protocol.startsWith('socks')) {
|
|
31
|
+
uri.port = '1080';
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
|
-
if (!uri.username
|
|
35
|
-
|
|
34
|
+
if (!uri.username) {
|
|
35
|
+
const username = proxy.username || options.username || auth.username;
|
|
36
|
+
if (username) uri.username = username;
|
|
36
37
|
}
|
|
37
|
-
if (!uri.password
|
|
38
|
-
|
|
38
|
+
if (!uri.password) {
|
|
39
|
+
const password = proxy.password || options.password || auth.password;
|
|
40
|
+
if (password) uri.password = password;
|
|
39
41
|
}
|
|
40
42
|
return uri.toString();
|
|
41
43
|
}
|