dv-browser 2.1.3 → 2.3.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 +34 -32
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
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 (config) {
|
|
10
|
+
if (!config) config = { };
|
|
11
|
+
config.timeout = config.timeout ?? 15;
|
|
12
|
+
config.connectTimeout = config.connectTimeout ?? 5;
|
|
13
|
+
config.httpProxy = config.timeout ?? null;
|
|
14
|
+
config.httpProxyUserPwd = config.timeout ?? null;
|
|
15
|
+
config.allowRedirect = config.timeout ?? 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';
|
|
9
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
|
-
};
|
|
24
|
-
|
|
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,19 @@ let DvBrowser = function () {
|
|
|
62
63
|
if (cookieString) {
|
|
63
64
|
headers.push('Cookie: ' + cookieString);
|
|
64
65
|
}
|
|
65
|
-
if (
|
|
66
|
-
headers.push('
|
|
67
|
-
}
|
|
68
|
-
if (options.contentType) {
|
|
69
|
-
headers.push('Content-Type: ' + options.contentType);
|
|
66
|
+
if (options['contentType']) {
|
|
67
|
+
headers.push('Content-Type: ' + options['contentType']);
|
|
70
68
|
} else if (method === 'POST') {
|
|
71
69
|
headers.push('Content-Type: application/x-www-form-urlencoded');
|
|
72
70
|
}
|
|
73
|
-
headers.push('
|
|
74
|
-
headers.push('Accept
|
|
75
|
-
headers.push('
|
|
76
|
-
|
|
71
|
+
headers.push('Connection: ' + (options['connection'] ?? 'close'));
|
|
72
|
+
headers.push('Accept: ' + (options['accept'] ?? config['accept']));
|
|
73
|
+
headers.push('Accept-Language: ' + (options['acceptLanguage'] ?? config['acceptLanguage']));
|
|
74
|
+
headers.push('User-Agent: ' + (options['userAgent'] ?? config['userAgent']));
|
|
75
|
+
if (options['referer'] || referer) {
|
|
76
|
+
headers.push('Referer: ' + (options['referer'] ?? referer));
|
|
77
|
+
}
|
|
78
|
+
if (!options['noDeflate']) {
|
|
77
79
|
headers.push('Accept-Encoding: gzip, deflate');
|
|
78
80
|
}
|
|
79
81
|
if (options['headers']) {
|
|
@@ -108,7 +110,7 @@ let DvBrowser = function () {
|
|
|
108
110
|
curl.setOpt(Curl.option.FOLLOWLOCATION, config.allowRedirect);
|
|
109
111
|
curl.setOpt(Curl.option.SSL_VERIFYHOST, false);
|
|
110
112
|
curl.setOpt(Curl.option.SSL_VERIFYPEER, false);
|
|
111
|
-
if (!options
|
|
113
|
+
if (!options['noDeflate']) {
|
|
112
114
|
curl.setOpt(Curl.option.ACCEPT_ENCODING, 'gzip');
|
|
113
115
|
}
|
|
114
116
|
if (config.httpProxy) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dv-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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
|
}
|