unprint 0.13.3 → 0.14.0
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 +8 -0
- package/package.json +2 -1
- package/src/app.js +22 -7
- package/tests/init.js +6 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Simplify common web scraping tasks while staying in control of the data.",
|
|
5
5
|
"main": "src/app.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"eslint": "^8.17.0",
|
|
29
29
|
"eslint-config-airbnb": "^19.0.4",
|
|
30
30
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
31
|
+
"https-proxy-agent": "^7.0.5",
|
|
31
32
|
"jsdom": "^17.0.0",
|
|
32
33
|
"moment-timezone": "^0.5.34"
|
|
33
34
|
},
|
package/src/app.js
CHANGED
|
@@ -5,6 +5,7 @@ const EventEmitter = require('events');
|
|
|
5
5
|
const http = require('http');
|
|
6
6
|
const https = require('https');
|
|
7
7
|
const axios = require('axios').default;
|
|
8
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
8
9
|
const Bottleneck = require('bottleneck');
|
|
9
10
|
const moment = require('moment-timezone');
|
|
10
11
|
const merge = require('deepmerge');
|
|
@@ -948,17 +949,31 @@ async function request(url, body, customOptions = {}, method = 'GET') {
|
|
|
948
949
|
|
|
949
950
|
events.emit('requestInit', feedbackBase);
|
|
950
951
|
|
|
951
|
-
const
|
|
952
|
-
url,
|
|
953
|
-
method,
|
|
952
|
+
const instance = axios.create({
|
|
954
953
|
data: body,
|
|
955
954
|
validateStatus: null,
|
|
956
|
-
|
|
955
|
+
headers: options.headers,
|
|
957
956
|
timeout: options.timeout,
|
|
958
957
|
signal: options.abortSignal,
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
})
|
|
958
|
+
// ...options,
|
|
959
|
+
// httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
if (options.proxy) {
|
|
963
|
+
// instance.defaults.httpAgent = new HttpsProxyAgent(`http://${options.proxy.host}:${options.proxy.port}`, { ...options.agent });
|
|
964
|
+
instance.defaults.httpsAgent = options.httpsAgent || new HttpsProxyAgent(`http://${options.proxy.host}:${options.proxy.port}`, { ...options.agent });
|
|
965
|
+
|
|
966
|
+
instance.defaults.proxy = {
|
|
967
|
+
protocol: 'http',
|
|
968
|
+
host: options.proxy.host,
|
|
969
|
+
port: options.proxy.port,
|
|
970
|
+
};
|
|
971
|
+
} else {
|
|
972
|
+
instance.defaults.httpAgent = options.httpsAgent || new http.Agent({ ...options.agent });
|
|
973
|
+
instance.defaults.httpsAgent = options.httpsAgent || new https.Agent({ ...options.agent });
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const res = await limiter.schedule(async () => instance.get(url));
|
|
962
977
|
|
|
963
978
|
if (!(res.status >= 200 && res.status < 300)) {
|
|
964
979
|
handleError(new Error(`HTTP response from ${url} not OK (${res.status} ${res.statusText}): ${res.data}`), 'HTTP_NOT_OK');
|