mm_https 1.5.1 → 1.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.
- package/index.js +13 -11
- package/package.json +1 -1
- package/test.js +14 -9
- package/logonew.png +0 -0
package/index.js
CHANGED
|
@@ -38,7 +38,7 @@ class Http {
|
|
|
38
38
|
// 'sec-fetch-mode': 'navigate',
|
|
39
39
|
// 'sec-fetch-site': 'none',
|
|
40
40
|
// 'sec-fetch-user': '?1',
|
|
41
|
-
'Upgrade-Insecure-Requests': '1',
|
|
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,
|
|
@@ -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,13 +209,13 @@ Http.prototype.req = async function(options) {
|
|
|
207
209
|
this.post_option(op);
|
|
208
210
|
}
|
|
209
211
|
var res = await this.request(op);
|
|
210
|
-
if (res.
|
|
211
|
-
var url = headers.location;
|
|
212
|
-
var lt = headers['set-cookie'];
|
|
212
|
+
if (res.status.code == 302) {
|
|
213
|
+
var url = res.headers.location;
|
|
214
|
+
var lt = res.headers['set-cookie'];
|
|
213
215
|
if (lt) {
|
|
214
216
|
var len = lt.length;
|
|
215
217
|
for (var i = 0; i < len; i++) {
|
|
216
|
-
|
|
218
|
+
this.set_cookie(lt[i]);
|
|
217
219
|
}
|
|
218
220
|
options.href = url;
|
|
219
221
|
op = this.http_options(options);
|
|
@@ -262,21 +264,20 @@ Http.prototype.undata = function(encoding) {
|
|
|
262
264
|
* @param {Object} options 配置
|
|
263
265
|
*/
|
|
264
266
|
Http.prototype.request = function(options) {
|
|
265
|
-
var hp = options.
|
|
266
|
-
delete options.protocol;
|
|
267
|
+
var hp = options.host_protocol === "https" ? https : http;
|
|
267
268
|
var _this = this;
|
|
268
269
|
return new Promise(function(resolve, reject) {
|
|
269
270
|
var body = '';
|
|
270
271
|
var req = hp.request(options, (res) => {
|
|
272
|
+
var {
|
|
273
|
+
headers
|
|
274
|
+
} = res;
|
|
271
275
|
if (res.statusCode == 200) {
|
|
272
|
-
var {
|
|
273
|
-
headers
|
|
274
|
-
} = res;
|
|
275
276
|
var chunks = [];
|
|
276
277
|
var encoding = headers['content-encoding'];
|
|
277
278
|
res.on('data', function(d) {
|
|
278
279
|
chunks.push(d);
|
|
279
|
-
}).on('end', function(
|
|
280
|
+
}).on('end', function(de) {
|
|
280
281
|
var buffer = Buffer.concat(chunks);
|
|
281
282
|
switch (encoding) {
|
|
282
283
|
case 'br':
|
|
@@ -308,6 +309,7 @@ Http.prototype.request = function(options) {
|
|
|
308
309
|
});
|
|
309
310
|
} else {
|
|
310
311
|
resolve({
|
|
312
|
+
headers,
|
|
311
313
|
status: {
|
|
312
314
|
code: res.statusCode,
|
|
313
315
|
message: res.statusMessage
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
// const nJwt = require('njwt');
|
|
2
|
-
var http = require('http');
|
|
3
2
|
var Http = require('./index.js');
|
|
4
3
|
var fs = require("fs");
|
|
5
4
|
|
|
5
|
+
async function test(){
|
|
6
|
+
var http = new Http();
|
|
7
|
+
var res = await http.get("https://www.baidu.com/");
|
|
8
|
+
// var res = await http.get("https://1689622.com/view/jisusaiche/pk10kai.html");
|
|
9
|
+
console.log("html", res);
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
// async function test3() {
|
|
7
13
|
// // 将「微信对话开放平台」得到的信息填入
|
|
8
14
|
// var APPID = "xxx";
|
|
@@ -25,7 +31,6 @@ var fs = require("fs");
|
|
|
25
31
|
// }
|
|
26
32
|
// test3();
|
|
27
33
|
|
|
28
|
-
|
|
29
34
|
// async function test2(content, from_user) {.
|
|
30
35
|
// 图灵机器人
|
|
31
36
|
// const apikey = "xxx";
|
|
@@ -104,13 +109,13 @@ var fs = require("fs");
|
|
|
104
109
|
// }
|
|
105
110
|
|
|
106
111
|
|
|
107
|
-
async function test() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
112
|
+
// async function test() {
|
|
113
|
+
// var hp = new Http();
|
|
114
|
+
// hp.config.headers.Accept = "application/javascript; charset=UTF-8";
|
|
115
|
+
// var url ="http://localhost:8001/api/wallet/count";
|
|
116
|
+
// var res = await hp.get(url);
|
|
117
|
+
// console.log(res);
|
|
118
|
+
// }
|
|
114
119
|
|
|
115
120
|
// async function test() {
|
|
116
121
|
// console.log("测试")
|
package/logonew.png
DELETED
|
Binary file
|