dv-browser 2.2.0 → 2.3.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 +17 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,23 +6,23 @@ let CurlIpResolve = require('node-libcurl').CurlIpResolve;
|
|
|
6
6
|
let Cookie = require('tough-cookie').Cookie;
|
|
7
7
|
let CookieJar = require('tough-cookie').CookieJar;
|
|
8
8
|
|
|
9
|
-
let DvBrowser = function (
|
|
9
|
+
let DvBrowser = function (config) {
|
|
10
|
+
if (!config) config = { };
|
|
11
|
+
config.timeout = config.timeout ?? 15;
|
|
12
|
+
config.connectTimeout = config.connectTimeout ?? 5;
|
|
13
|
+
config.httpProxy = config.httpProxy ?? null;
|
|
14
|
+
config.httpProxyUserPwd = config.httpProxyUserPwd ?? null;
|
|
15
|
+
config.allowRedirect = config.allowRedirect ?? true;
|
|
16
|
+
config.userAgent = config.userAgent ?? 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36';
|
|
17
|
+
config.accept = config.accept ?? 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
|
|
18
|
+
config.acceptLanguage = config.acceptLanguage ?? 'ru,en-US,en;q=0.8,ru;q=0.6';
|
|
19
|
+
|
|
10
20
|
let globalHeaders = [
|
|
11
|
-
'Connection: close',
|
|
12
21
|
'Cache-Control: max-age=0',
|
|
13
22
|
'Proxy-Connection: close',
|
|
14
23
|
'Expect: ' // remove "Expect: 100-continue" header
|
|
15
24
|
];
|
|
16
25
|
|
|
17
|
-
let config = {
|
|
18
|
-
timeout: 15,
|
|
19
|
-
connectTimeout: 5,
|
|
20
|
-
httpProxy: null,
|
|
21
|
-
httpProxyUserPwd: null,
|
|
22
|
-
allowRedirect: true,
|
|
23
|
-
userAgent: opts['userAgent'] ?? 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
26
|
let cookiejar = new CookieJar();
|
|
27
27
|
let referer = '';
|
|
28
28
|
|
|
@@ -63,17 +63,18 @@ let DvBrowser = function (opts) {
|
|
|
63
63
|
if (cookieString) {
|
|
64
64
|
headers.push('Cookie: ' + cookieString);
|
|
65
65
|
}
|
|
66
|
-
if (options['referer'] || referer) {
|
|
67
|
-
headers.push('Referer: ' + (options['referer'] ?? referer));
|
|
68
|
-
}
|
|
69
66
|
if (options['contentType']) {
|
|
70
67
|
headers.push('Content-Type: ' + options['contentType']);
|
|
71
68
|
} else if (method === 'POST') {
|
|
72
69
|
headers.push('Content-Type: application/x-www-form-urlencoded');
|
|
73
70
|
}
|
|
74
|
-
headers.push('
|
|
75
|
-
headers.push('Accept
|
|
71
|
+
headers.push('Connection: ' + (options['connection'] ?? 'close'));
|
|
72
|
+
headers.push('Accept: ' + (options['accept'] ?? config['accept']));
|
|
73
|
+
headers.push('Accept-Language: ' + (options['acceptLanguage'] ?? config['acceptLanguage']));
|
|
76
74
|
headers.push('User-Agent: ' + (options['userAgent'] ?? config['userAgent']));
|
|
75
|
+
if (options['referer'] || referer) {
|
|
76
|
+
headers.push('Referer: ' + (options['referer'] ?? referer));
|
|
77
|
+
}
|
|
77
78
|
if (!options['noDeflate']) {
|
|
78
79
|
headers.push('Accept-Encoding: gzip, deflate');
|
|
79
80
|
}
|