unprint 0.14.1 → 0.14.2
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/README.md +18 -3
- package/package.json +1 -1
- package/src/app.js +29 -14
- package/tests/init.js +1 -2
package/README.md
CHANGED
|
@@ -209,9 +209,24 @@ Returns
|
|
|
209
209
|
|
|
210
210
|
### Proxy
|
|
211
211
|
```javascript
|
|
212
|
-
unprint.
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
unprint.options({ // or unprint.options();
|
|
213
|
+
proxy: {
|
|
214
|
+
enable: true,
|
|
215
|
+
use: false, // don't use for all requests by default
|
|
216
|
+
host: '127.0.0.1',
|
|
217
|
+
port: 8888,
|
|
218
|
+
hostnames: [
|
|
219
|
+
'www.google.com',
|
|
220
|
+
'www.example.com',
|
|
221
|
+
],
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
unprint.get({
|
|
226
|
+
proxy: {
|
|
227
|
+
use: true, // use proxy for this request
|
|
228
|
+
// all other proxy options can be supplied here
|
|
229
|
+
},
|
|
215
230
|
});
|
|
216
231
|
```
|
|
217
232
|
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -930,6 +930,34 @@ function getLimiter(url, options) {
|
|
|
930
930
|
};
|
|
931
931
|
}
|
|
932
932
|
|
|
933
|
+
/* eslint-disable no-param-reassign */
|
|
934
|
+
function setProxy(instance, options, url) {
|
|
935
|
+
const { hostname } = new URL(url);
|
|
936
|
+
|
|
937
|
+
if (options.proxy
|
|
938
|
+
&& options.proxy.enable !== false
|
|
939
|
+
&& options.proxy.use !== false // use is a local override for enable
|
|
940
|
+
&& (options.proxy.use
|
|
941
|
+
|| options.proxy.hostnames?.includes(hostname))
|
|
942
|
+
) {
|
|
943
|
+
const proxyAgent = tunnel.httpsOverHttp({
|
|
944
|
+
proxy: {
|
|
945
|
+
host: options.proxy.host,
|
|
946
|
+
port: options.proxy.port,
|
|
947
|
+
},
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
instance.defaults.httpAgent = proxyAgent;
|
|
951
|
+
instance.defaults.httpsAgent = proxyAgent;
|
|
952
|
+
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
instance.defaults.httpAgent = options.httpsAgent || new http.Agent({ ...options.agent });
|
|
957
|
+
instance.defaults.httpsAgent = options.httpsAgent || new https.Agent({ ...options.agent });
|
|
958
|
+
}
|
|
959
|
+
/* eslint-enable no-param-reassign */
|
|
960
|
+
|
|
933
961
|
async function request(url, body, customOptions = {}, method = 'GET') {
|
|
934
962
|
const options = merge.all([{
|
|
935
963
|
timeout: 1000,
|
|
@@ -959,20 +987,7 @@ async function request(url, body, customOptions = {}, method = 'GET') {
|
|
|
959
987
|
// httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
|
|
960
988
|
});
|
|
961
989
|
|
|
962
|
-
|
|
963
|
-
const proxyAgent = tunnel.httpsOverHttp({
|
|
964
|
-
proxy: {
|
|
965
|
-
host: options.proxy.host,
|
|
966
|
-
port: options.proxy.port,
|
|
967
|
-
},
|
|
968
|
-
});
|
|
969
|
-
|
|
970
|
-
instance.defaults.httpAgent = proxyAgent;
|
|
971
|
-
instance.defaults.httpsAgent = proxyAgent;
|
|
972
|
-
} else {
|
|
973
|
-
instance.defaults.httpAgent = options.httpsAgent || new http.Agent({ ...options.agent });
|
|
974
|
-
instance.defaults.httpsAgent = options.httpsAgent || new https.Agent({ ...options.agent });
|
|
975
|
-
}
|
|
990
|
+
setProxy(instance, options, url);
|
|
976
991
|
|
|
977
992
|
const res = await limiter.schedule(async () => instance.get(url));
|
|
978
993
|
|
package/tests/init.js
CHANGED