dv-browser 2.1.3 → 2.2.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/index.js +23 -22
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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
|
-
let self = this;
|
|
9
|
-
|
|
9
|
+
let DvBrowser = function (opts) {
|
|
10
10
|
let globalHeaders = [
|
|
11
11
|
'Connection: close',
|
|
12
12
|
'Cache-Control: max-age=0',
|
|
@@ -19,19 +19,20 @@ let DvBrowser = function () {
|
|
|
19
19
|
connectTimeout: 5,
|
|
20
20
|
httpProxy: null,
|
|
21
21
|
httpProxyUserPwd: null,
|
|
22
|
-
allowRedirect: true
|
|
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',
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
let cookiejar = new CookieJar();
|
|
26
27
|
let referer = '';
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
this.getProxy = function () { return config.httpProxy; };
|
|
30
|
+
this.setProxy = function (host, creds) { config.httpProxy = host; config.httpProxyUserPwd = creds; };
|
|
31
|
+
this.setReferer = function (url) { referer = url; };
|
|
32
|
+
this.setCookie = function (cookie, url, options) { cookiejar.setCookieSync(cookie, url, options); };
|
|
33
|
+
this.setTimeout = function (connect, read) { config.connectTimeout = connect; config.timeout = read; };
|
|
34
|
+
this.setAllowRedirect = function (allowRedirect) { config.allowRedirect = allowRedirect };
|
|
35
|
+
this.getCookie = function (key, url) {
|
|
35
36
|
let cookies = cookiejar.getCookiesSync(url);
|
|
36
37
|
for (let cookie of cookies) {
|
|
37
38
|
if (cookie.key === key) {
|
|
@@ -41,14 +42,14 @@ let DvBrowser = function () {
|
|
|
41
42
|
return null;
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
this.get = function (url, options) {
|
|
45
46
|
if (!options) options = { };
|
|
46
47
|
options.url = url;
|
|
47
48
|
return processRequest('GET', options);
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
this.post = function (url, postData) { return processRequest('POST', { url: url, postData: postData }); };
|
|
51
|
+
this.postEx = function (options) { return processRequest('POST', options); };
|
|
52
|
+
this.request = function (method, options) { return processRequest(method, options); };
|
|
52
53
|
|
|
53
54
|
function processRequest(method, options) {
|
|
54
55
|
return new Promise((resolve, reject) => {
|
|
@@ -62,18 +63,18 @@ let DvBrowser = function () {
|
|
|
62
63
|
if (cookieString) {
|
|
63
64
|
headers.push('Cookie: ' + cookieString);
|
|
64
65
|
}
|
|
65
|
-
if (referer) {
|
|
66
|
-
headers.push('Referer: ' + referer);
|
|
66
|
+
if (options['referer'] || referer) {
|
|
67
|
+
headers.push('Referer: ' + (options['referer'] ?? referer));
|
|
67
68
|
}
|
|
68
|
-
if (options
|
|
69
|
-
headers.push('Content-Type: ' + options
|
|
69
|
+
if (options['contentType']) {
|
|
70
|
+
headers.push('Content-Type: ' + options['contentType']);
|
|
70
71
|
} else if (method === 'POST') {
|
|
71
72
|
headers.push('Content-Type: application/x-www-form-urlencoded');
|
|
72
73
|
}
|
|
73
74
|
headers.push('Accept: ' + (options['accept'] ? options['accept'] : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'));
|
|
74
75
|
headers.push('Accept-Language: ' + (options['acceptLanguage'] ? options['acceptLanguage'] : 'ru,en-US,en;q=0.8,ru;q=0.6'));
|
|
75
|
-
headers.push('User-Agent: ' + (options['userAgent']
|
|
76
|
-
if (!options
|
|
76
|
+
headers.push('User-Agent: ' + (options['userAgent'] ?? config['userAgent']));
|
|
77
|
+
if (!options['noDeflate']) {
|
|
77
78
|
headers.push('Accept-Encoding: gzip, deflate');
|
|
78
79
|
}
|
|
79
80
|
if (options['headers']) {
|
|
@@ -108,7 +109,7 @@ let DvBrowser = function () {
|
|
|
108
109
|
curl.setOpt(Curl.option.FOLLOWLOCATION, config.allowRedirect);
|
|
109
110
|
curl.setOpt(Curl.option.SSL_VERIFYHOST, false);
|
|
110
111
|
curl.setOpt(Curl.option.SSL_VERIFYPEER, false);
|
|
111
|
-
if (!options
|
|
112
|
+
if (!options['noDeflate']) {
|
|
112
113
|
curl.setOpt(Curl.option.ACCEPT_ENCODING, 'gzip');
|
|
113
114
|
}
|
|
114
115
|
if (config.httpProxy) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dv-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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
|
}
|