dv-browser 2.1.2 → 2.2.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 +26 -31
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
|
|
1
3
|
"use strict";
|
|
2
4
|
let Curl = require('node-libcurl').Curl;
|
|
3
5
|
let CurlIpResolve = require('node-libcurl').CurlIpResolve;
|
|
4
6
|
let Cookie = require('tough-cookie').Cookie;
|
|
5
7
|
let CookieJar = require('tough-cookie').CookieJar;
|
|
6
8
|
|
|
7
|
-
let DvBrowser = function () {
|
|
8
|
-
|
|
9
|
+
let DvBrowser = function (opts) {
|
|
10
|
+
if (!opts) opts = { };
|
|
9
11
|
|
|
10
12
|
let globalHeaders = [
|
|
11
|
-
'Accept-Language: ru,en-US,en;q=0.8,ru;q=0.6',
|
|
12
13
|
'Connection: close',
|
|
13
14
|
'Cache-Control: max-age=0',
|
|
14
15
|
'Proxy-Connection: close',
|
|
@@ -20,19 +21,20 @@ let DvBrowser = function () {
|
|
|
20
21
|
connectTimeout: 5,
|
|
21
22
|
httpProxy: null,
|
|
22
23
|
httpProxyUserPwd: null,
|
|
23
|
-
allowRedirect: true
|
|
24
|
+
allowRedirect: true,
|
|
25
|
+
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
26
|
};
|
|
25
27
|
|
|
26
28
|
let cookiejar = new CookieJar();
|
|
27
29
|
let referer = '';
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
this.getProxy = function () { return config.httpProxy; };
|
|
32
|
+
this.setProxy = function (host, creds) { config.httpProxy = host; config.httpProxyUserPwd = creds; };
|
|
33
|
+
this.setReferer = function (url) { referer = url; };
|
|
34
|
+
this.setCookie = function (cookie, url, options) { cookiejar.setCookieSync(cookie, url, options); };
|
|
35
|
+
this.setTimeout = function (connect, read) { config.connectTimeout = connect; config.timeout = read; };
|
|
36
|
+
this.setAllowRedirect = function (allowRedirect) { config.allowRedirect = allowRedirect };
|
|
37
|
+
this.getCookie = function (key, url) {
|
|
36
38
|
let cookies = cookiejar.getCookiesSync(url);
|
|
37
39
|
for (let cookie of cookies) {
|
|
38
40
|
if (cookie.key === key) {
|
|
@@ -42,14 +44,14 @@ let DvBrowser = function () {
|
|
|
42
44
|
return null;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
this.get = function (url, options) {
|
|
46
48
|
if (!options) options = { };
|
|
47
49
|
options.url = url;
|
|
48
50
|
return processRequest('GET', options);
|
|
49
51
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
this.post = function (url, postData) { return processRequest('POST', { url: url, postData: postData }); };
|
|
53
|
+
this.postEx = function (options) { return processRequest('POST', options); };
|
|
54
|
+
this.request = function (method, options) { return processRequest(method, options); };
|
|
53
55
|
|
|
54
56
|
function processRequest(method, options) {
|
|
55
57
|
return new Promise((resolve, reject) => {
|
|
@@ -63,25 +65,18 @@ let DvBrowser = function () {
|
|
|
63
65
|
if (cookieString) {
|
|
64
66
|
headers.push('Cookie: ' + cookieString);
|
|
65
67
|
}
|
|
66
|
-
if (referer) {
|
|
67
|
-
headers.push('Referer: ' + referer);
|
|
68
|
+
if (options['referer'] || referer) {
|
|
69
|
+
headers.push('Referer: ' + (options['referer'] ?? referer));
|
|
68
70
|
}
|
|
69
|
-
if (options
|
|
70
|
-
headers.push('Content-Type: ' + options
|
|
71
|
+
if (options['contentType']) {
|
|
72
|
+
headers.push('Content-Type: ' + options['contentType']);
|
|
71
73
|
} else if (method === 'POST') {
|
|
72
74
|
headers.push('Content-Type: application/x-www-form-urlencoded');
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
if (options.userAgent) {
|
|
80
|
-
headers.push('User-Agent: ' + options.userAgent);
|
|
81
|
-
} else {
|
|
82
|
-
headers.push('User-Agent: 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');
|
|
83
|
-
}
|
|
84
|
-
if (!options.noDeflate) {
|
|
76
|
+
headers.push('Accept: ' + (options['accept'] ? options['accept'] : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'));
|
|
77
|
+
headers.push('Accept-Language: ' + (options['acceptLanguage'] ? options['acceptLanguage'] : 'ru,en-US,en;q=0.8,ru;q=0.6'));
|
|
78
|
+
headers.push('User-Agent: ' + (options['userAgent'] ?? config['userAgent']));
|
|
79
|
+
if (!options['noDeflate']) {
|
|
85
80
|
headers.push('Accept-Encoding: gzip, deflate');
|
|
86
81
|
}
|
|
87
82
|
if (options['headers']) {
|
|
@@ -116,7 +111,7 @@ let DvBrowser = function () {
|
|
|
116
111
|
curl.setOpt(Curl.option.FOLLOWLOCATION, config.allowRedirect);
|
|
117
112
|
curl.setOpt(Curl.option.SSL_VERIFYHOST, false);
|
|
118
113
|
curl.setOpt(Curl.option.SSL_VERIFYPEER, false);
|
|
119
|
-
if (!options
|
|
114
|
+
if (!options['noDeflate']) {
|
|
120
115
|
curl.setOpt(Curl.option.ACCEPT_ENCODING, 'gzip');
|
|
121
116
|
}
|
|
122
117
|
if (config.httpProxy) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dv-browser",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/druidvav/node-browser",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"node-libcurl": "
|
|
21
|
-
"tough-cookie": "
|
|
20
|
+
"node-libcurl": "2.3.4",
|
|
21
|
+
"tough-cookie": "4.0.0"
|
|
22
22
|
}
|
|
23
23
|
}
|