unprint 0.13.3 → 0.14.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/README.md +8 -0
- package/package.json +3 -2
- package/src/app.js +23 -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.1",
|
|
4
4
|
"description": "Simplify common web scraping tasks while staying in control of the data.",
|
|
5
5
|
"main": "src/app.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"eslint-config-airbnb": "^19.0.4",
|
|
30
30
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
31
31
|
"jsdom": "^17.0.0",
|
|
32
|
-
"moment-timezone": "^0.5.34"
|
|
32
|
+
"moment-timezone": "^0.5.34",
|
|
33
|
+
"tunnel": "^0.0.6"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"express": "^4.18.1"
|
package/src/app.js
CHANGED
|
@@ -4,6 +4,7 @@ const { JSDOM, VirtualConsole } = require('jsdom');
|
|
|
4
4
|
const EventEmitter = require('events');
|
|
5
5
|
const http = require('http');
|
|
6
6
|
const https = require('https');
|
|
7
|
+
const tunnel = require('tunnel');
|
|
7
8
|
const axios = require('axios').default;
|
|
8
9
|
const Bottleneck = require('bottleneck');
|
|
9
10
|
const moment = require('moment-timezone');
|
|
@@ -948,17 +949,32 @@ 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
|
+
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
|
+
}
|
|
976
|
+
|
|
977
|
+
const res = await limiter.schedule(async () => instance.get(url));
|
|
962
978
|
|
|
963
979
|
if (!(res.status >= 200 && res.status < 300)) {
|
|
964
980
|
handleError(new Error(`HTTP response from ${url} not OK (${res.status} ${res.statusText}): ${res.data}`), 'HTTP_NOT_OK');
|