mm_https 1.5.2 → 1.5.5
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 +5 -5
- package/package.json +1 -1
- package/test.js +1 -2
package/index.js
CHANGED
|
@@ -39,7 +39,7 @@ class Http {
|
|
|
39
39
|
// 'sec-fetch-site': 'none',
|
|
40
40
|
// 'sec-fetch-user': '?1',
|
|
41
41
|
// 'Upgrade-Insecure-Requests': '1',
|
|
42
|
-
|
|
42
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
|
|
43
43
|
},
|
|
44
44
|
rejectUnauthorized: false,
|
|
45
45
|
cookie: "",
|
|
@@ -103,7 +103,9 @@ Http.prototype.http_options = function(options) {
|
|
|
103
103
|
if (cookie) {
|
|
104
104
|
this.set_cookie(cookie);
|
|
105
105
|
}
|
|
106
|
+
var host_protocol = href.left(":/") || 'http';
|
|
106
107
|
return Object.assign({}, {
|
|
108
|
+
host_protocol,
|
|
107
109
|
body,
|
|
108
110
|
type,
|
|
109
111
|
method: method || "GET",
|
|
@@ -207,7 +209,6 @@ Http.prototype.req = async function(options) {
|
|
|
207
209
|
this.post_option(op);
|
|
208
210
|
}
|
|
209
211
|
var res = await this.request(op);
|
|
210
|
-
console.log(op);
|
|
211
212
|
if (res.status.code == 302) {
|
|
212
213
|
var url = res.headers.location;
|
|
213
214
|
var lt = res.headers['set-cookie'];
|
|
@@ -263,8 +264,7 @@ Http.prototype.undata = function(encoding) {
|
|
|
263
264
|
* @param {Object} options 配置
|
|
264
265
|
*/
|
|
265
266
|
Http.prototype.request = function(options) {
|
|
266
|
-
var hp = options.
|
|
267
|
-
delete options.protocol;
|
|
267
|
+
var hp = options.host_protocol === "https" ? https : http;
|
|
268
268
|
var _this = this;
|
|
269
269
|
return new Promise(function(resolve, reject) {
|
|
270
270
|
var body = '';
|
|
@@ -277,7 +277,7 @@ Http.prototype.request = function(options) {
|
|
|
277
277
|
var encoding = headers['content-encoding'];
|
|
278
278
|
res.on('data', function(d) {
|
|
279
279
|
chunks.push(d);
|
|
280
|
-
}).on('end', function(
|
|
280
|
+
}).on('end', function(de) {
|
|
281
281
|
var buffer = Buffer.concat(chunks);
|
|
282
282
|
switch (encoding) {
|
|
283
283
|
case 'br':
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -4,8 +4,7 @@ var fs = require("fs");
|
|
|
4
4
|
|
|
5
5
|
async function test(){
|
|
6
6
|
var http = new Http();
|
|
7
|
-
|
|
8
|
-
var res = await http.get("https://www.hao123.com/");
|
|
7
|
+
var res = await http.get("https://www.baidu.com/");
|
|
9
8
|
console.log("html", res);
|
|
10
9
|
}
|
|
11
10
|
|