dv-browser 2.5.2 → 2.5.4

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.
Files changed (2) hide show
  1. package/index.js +21 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -17,11 +17,13 @@ let DvBrowser = function (_config) {
17
17
  cacheControl: 'max-age=0',
18
18
  connection: 'close',
19
19
  proxyConnection: 'close',
20
+ xhr: false,
21
+ authBearer: null,
22
+ noDeflate: false,
20
23
  }, _config);
21
24
 
22
25
  const cookiejar = new CookieJar(null);
23
26
 
24
- this.getProxy = function () { return config.httpProxy; };
25
27
  this.setCookie = function (cookie, url, options) { cookiejar.setCookieSync(cookie, url, options); };
26
28
  this.getCookie = function (key, url) {
27
29
  let cookies = cookiejar.getCookiesSync(url);
@@ -67,10 +69,11 @@ let DvBrowser = function (_config) {
67
69
  if (cookieString) {
68
70
  headers.push('Cookie: ' + cookieString);
69
71
  }
70
- if (options['contentType']) {
71
- headers.push('Content-Type: ' + options['contentType']);
72
- } else if (method === 'POST') {
73
- headers.push('Content-Type: application/x-www-form-urlencoded');
72
+ if (!options.contentType && options.postData) {
73
+ options.contentType = 'application/x-www-form-urlencoded';
74
+ }
75
+ if (options.contentType) {
76
+ headers.push('Content-Type: ' + options.contentType);
74
77
  }
75
78
  headers.push('Connection: ' + options['connection']);
76
79
  headers.push('Accept: ' + options['accept']);
@@ -78,8 +81,18 @@ let DvBrowser = function (_config) {
78
81
  headers.push('User-Agent: ' + options['userAgent']);
79
82
  headers.push('Cache-Control: ' + options['cacheControl']);
80
83
  headers.push('Proxy-Connection: ' + options['proxyConnection']);
81
- if (options['referer']) headers.push('Referer: ' + options['referer']);
82
- if (!options['noDeflate']) headers.push('Accept-Encoding: gzip, deflate');
84
+ if (options.referer) {
85
+ headers.push('Referer: ' + options.referer);
86
+ }
87
+ if (!options.noDeflate) {
88
+ headers.push('Accept-Encoding: gzip, deflate');
89
+ }
90
+ if (options.xhr) {
91
+ headers.push('X-Requested-With: XMLHttpRequest');
92
+ }
93
+ if (options.authBearer) {
94
+ headers.push('Authorization: Bearer ' + options.authBearer);
95
+ }
83
96
  if (options['headers']) {
84
97
  for (let i = 0; i < options['headers'].length; i++) {
85
98
  headers.push(options['headers'][i]);
@@ -113,7 +126,7 @@ let DvBrowser = function (_config) {
113
126
  curl.setOpt(Curl.option.FOLLOWLOCATION, options.allowRedirect);
114
127
  curl.setOpt(Curl.option.SSL_VERIFYHOST, false);
115
128
  curl.setOpt(Curl.option.SSL_VERIFYPEER, false);
116
- if (!options['noDeflate']) {
129
+ if (!options.noDeflate) {
117
130
  curl.setOpt(Curl.option.ACCEPT_ENCODING, 'gzip');
118
131
  }
119
132
  if (options.httpProxy) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dv-browser",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {