mm_https 1.6.3 → 1.6.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/README.md +220 -220
- package/index.js +200 -169
- package/npm-publish-checklist.md +99 -0
- package/package.json +15 -13
- package/test.js +160 -209
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_https",
|
|
3
|
-
"version": "1.6.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.6.4",
|
|
4
|
+
"description": "超级美眉HTTP请求模块 - 支持自动Cookie管理、代理设置、文件下载等功能",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node test.js",
|
|
@@ -12,17 +12,16 @@
|
|
|
12
12
|
"url": "git+https://gitee.com/qiuwenwu91/mm_https.git"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
|
-
"
|
|
15
|
+
"http",
|
|
16
|
+
"https",
|
|
17
|
+
"request",
|
|
16
18
|
"async",
|
|
17
|
-
"await",
|
|
18
19
|
"promise",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"run",
|
|
25
|
-
"exec"
|
|
20
|
+
"cookie",
|
|
21
|
+
"proxy",
|
|
22
|
+
"download",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"http-client"
|
|
26
25
|
],
|
|
27
26
|
"author": "邱文武",
|
|
28
27
|
"license": "ISC",
|
|
@@ -30,9 +29,12 @@
|
|
|
30
29
|
"url": "https://gitee.com/qiuwenwu91/mm_https/issues"
|
|
31
30
|
},
|
|
32
31
|
"homepage": "https://gitee.com/qiuwenwu91/mm_https#readme",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=12.0.0"
|
|
34
|
+
},
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"https-proxy-agent": "^7.0.6",
|
|
35
|
-
"iconv-lite": "^0.
|
|
36
|
-
"mm_expand": "^1.
|
|
37
|
+
"iconv-lite": "^0.7.0",
|
|
38
|
+
"mm_expand": "^1.9.7"
|
|
37
39
|
}
|
|
38
40
|
}
|
package/test.js
CHANGED
|
@@ -1,215 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* mm_https模块测试文件
|
|
3
|
+
* 用于npm发布前的功能验证
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const Http = require('./index.js');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 基础HTTP请求测试
|
|
11
|
+
*/
|
|
12
|
+
async function testBasicRequests() {
|
|
13
|
+
console.log('=== 基础HTTP请求测试 ===');
|
|
14
|
+
|
|
15
|
+
const http = new Http();
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// 测试GET请求
|
|
19
|
+
console.log('1. 测试GET请求...');
|
|
20
|
+
const getRes = await http.get('https://httpbin.org/get');
|
|
21
|
+
console.log('GET请求状态码:', getRes.status);
|
|
22
|
+
console.log('GET请求成功');
|
|
23
|
+
|
|
24
|
+
// 测试POST请求
|
|
25
|
+
console.log('2. 测试POST请求...');
|
|
26
|
+
const postData = { test: 'data', value: 123 };
|
|
27
|
+
const postRes = await http.post('https://httpbin.org/post', postData);
|
|
28
|
+
console.log('POST请求状态码:', postRes.status);
|
|
29
|
+
console.log('POST请求成功');
|
|
30
|
+
|
|
31
|
+
// 测试Cookie管理
|
|
32
|
+
console.log('3. 测试Cookie管理...');
|
|
33
|
+
http.setCookie('session=test_session; user=test_user');
|
|
34
|
+
const cookieStr = http.getCookie();
|
|
35
|
+
console.log('当前Cookie:', cookieStr);
|
|
36
|
+
|
|
37
|
+
console.log('✅ 基础功能测试通过');
|
|
38
|
+
return true;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error('❌ 基础功能测试失败:', err.message);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
10
43
|
}
|
|
11
44
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// },
|
|
52
|
-
// "userInfo": {
|
|
53
|
-
// "apiKey": apikey,
|
|
54
|
-
// "userId": from_user
|
|
55
|
-
// }
|
|
56
|
-
// };
|
|
57
|
-
// //http://192.168.18.199:8000/test/hello
|
|
58
|
-
// var res = await hp.post("http://openapi.tuling123.com/openapi/api/v2", pm);
|
|
59
|
-
// console.log(res.body);
|
|
60
|
-
// }
|
|
61
|
-
// test2("真的", "we21lkjq3l");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// // 测试
|
|
65
|
-
// async function test() {
|
|
66
|
-
// var hp = new Http({
|
|
67
|
-
// proxy: "http://127.0.0.1:10809"
|
|
68
|
-
// });
|
|
69
|
-
// res = await hp.post("https://accounts.binance.com/bapi/accounts/v2/public/authcenter/login", {
|
|
70
|
-
// 'phone': "15817188815",
|
|
71
|
-
// 'password': "asd123"
|
|
72
|
-
// }, null, 'form');
|
|
73
|
-
// var token = hp.cookies['x-auth-token'];
|
|
74
|
-
// // res = await hp.get("http://api.bitcentre.com.cn/paper/id?id=1", {
|
|
75
|
-
// // "x-auth-token": token
|
|
76
|
-
// // });
|
|
77
|
-
|
|
78
|
-
// // res = await hp.get("https://www.google.com");
|
|
79
|
-
// console.log('结果:', res);
|
|
80
|
-
// console.log('结果:', hp.cookies);
|
|
81
|
-
// }
|
|
82
|
-
|
|
83
|
-
// 测试
|
|
84
|
-
// async function test() {
|
|
85
|
-
// var hp = new Http();
|
|
86
|
-
// // var res = await hp.get("http://www.baidu.com");
|
|
87
|
-
// // console.log('百度:' + JSON.stringify(res));
|
|
88
|
-
// res = await hp.post("http://127.0.0.1:8000/login", {
|
|
89
|
-
// 'phone': "15817188815",
|
|
90
|
-
// 'password': "asd123"
|
|
91
|
-
// }, null, 'json');
|
|
92
|
-
// console.log('登录:' + JSON.stringify(res));
|
|
93
|
-
// var token = hp.cookies['x-auth-token'];
|
|
94
|
-
// console.log('访问牌:' + token);
|
|
95
|
-
// // res = await hp.get("http://127.0.0.1:8000/paper/id?id=1", {
|
|
96
|
-
// // "x-auth-token": token || ""
|
|
97
|
-
// // });
|
|
98
|
-
// // console.log('结果:' + JSON.stringify(res));
|
|
99
|
-
// // console.log('结果:', hp.cookies);
|
|
100
|
-
// }
|
|
101
|
-
|
|
102
|
-
// async function test() {
|
|
103
|
-
// var hp = new Http();
|
|
104
|
-
// hp.config.headers.Accept = "application/javascript; charset=UTF-8";
|
|
105
|
-
// var url =
|
|
106
|
-
// "http://69.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124007023275733383882_1586573202818&pn=1&pz=100000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:13,m:0+t:80,m:1+t:2,m:1+t:23&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152";
|
|
107
|
-
// var res = await hp.get(url);
|
|
108
|
-
// console.log(res);
|
|
109
|
-
// }
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
// }
|
|
119
|
-
|
|
120
|
-
// async function test() {
|
|
121
|
-
// console.log("测试")
|
|
122
|
-
// var hp = new Http();
|
|
123
|
-
// var res = await hp.get('https://www.baidu.com/img/flexible/logo/pc/result.png');
|
|
124
|
-
// console.log(res);
|
|
125
|
-
// fs.writeFile("./logonew.png", res.buffer, "binary", function(err) {
|
|
126
|
-
// if (err) {
|
|
127
|
-
// console.log("下载失败");
|
|
128
|
-
// }
|
|
129
|
-
// console.log("下载成功");
|
|
130
|
-
// });
|
|
131
|
-
// }
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// async function test () {
|
|
135
|
-
// var hp = new Http();
|
|
136
|
-
// // var url = "http://vip.stock.finance.sina.com.cn/corp/view/vRPD_NewStockIssue.php?page=1&cngem=0&orderBy=NetDate&orderType=desc";
|
|
137
|
-
// var url = "http://www.sccnn.com/gaojingtuku/jierisucai/jianjunjie/20200724-264416.html";
|
|
138
|
-
// var res = await hp.get(url);
|
|
139
|
-
// console.log(res);
|
|
140
|
-
// }
|
|
141
|
-
// test();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// async function download(){
|
|
145
|
-
// var hp = new Http({
|
|
146
|
-
// headers: `
|
|
147
|
-
// Referer: https://www.aieliantong.com/admin/index
|
|
148
|
-
// X-Auth-Token: xxx
|
|
149
|
-
// `,
|
|
150
|
-
// cookie: "Hm_lvt_c73f94a74e41202e67d251e6e3f591cb=1697871513; Hm_lpvt_c73f94a74e41202e67d251e6e3f591cb=1698886851; mm:uuid=3QSuThREzVFdRW6/YrT0o0WpriBhXhMdnLmhtJOXwBg="
|
|
151
|
-
// });
|
|
152
|
-
// console.log(hp.headers, hp.cookies);
|
|
153
|
-
// var url = "https://www.copipi.com/p/224/224/becce1fc21d723614b598f5377d5d676.jpg";
|
|
154
|
-
// "./二维码/中文".addDir();
|
|
155
|
-
// var filename = "./二维码/qrcode.jpg".fullname();
|
|
156
|
-
// var file = await hp.download(url, filename);
|
|
157
|
-
// console.log(file);
|
|
158
|
-
// }
|
|
159
|
-
// download();
|
|
160
|
-
|
|
161
|
-
// async function test() {
|
|
162
|
-
// var http = new Http();
|
|
163
|
-
// console.log("开始请求");
|
|
164
|
-
// var options = http.new_options({
|
|
165
|
-
// url: "http://www.hao123.com:8000/test?dd=123"
|
|
166
|
-
// });
|
|
167
|
-
// console.log(1, options);
|
|
168
|
-
|
|
169
|
-
// options = http.new_options({
|
|
170
|
-
// url: "www.hao123.com:8000/test?dd=123"
|
|
171
|
-
// });
|
|
172
|
-
// console.log(2, options);
|
|
173
|
-
|
|
174
|
-
// options = http.new_options({
|
|
175
|
-
// url: "www.hao123.com/test?dd=123"
|
|
176
|
-
// });
|
|
177
|
-
// console.log(3, options);
|
|
178
|
-
|
|
179
|
-
// var options = http.new_options({
|
|
180
|
-
// url: "http://www.hao123.com/test?dd=123"
|
|
181
|
-
// });
|
|
182
|
-
// console.log(4, options);
|
|
183
|
-
|
|
184
|
-
// var options = http.new_options({
|
|
185
|
-
// url: "http://www.hao123.com"
|
|
186
|
-
// });
|
|
187
|
-
// console.log(5, options);
|
|
188
|
-
|
|
189
|
-
// options = http.new_options({
|
|
190
|
-
// url: "https://www.hao123.com:8000"
|
|
191
|
-
// });
|
|
192
|
-
// console.log(6, options);
|
|
45
|
+
/**
|
|
46
|
+
* 高级功能测试
|
|
47
|
+
*/
|
|
48
|
+
async function testAdvancedFeatures() {
|
|
49
|
+
console.log('\n=== 高级功能测试 ===');
|
|
50
|
+
|
|
51
|
+
const http = new Http({
|
|
52
|
+
headers: {
|
|
53
|
+
'User-Agent': 'Test-Agent/1.0'
|
|
54
|
+
},
|
|
55
|
+
cookie: 'initial=test_cookie'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// 测试自定义请求头
|
|
60
|
+
console.log('1. 测试自定义请求头...');
|
|
61
|
+
const headersRes = await http.get('https://httpbin.org/headers');
|
|
62
|
+
console.log('自定义请求头测试成功');
|
|
63
|
+
|
|
64
|
+
// 测试URL参数解析
|
|
65
|
+
console.log('2. 测试URL参数解析...');
|
|
66
|
+
const options = http.options();
|
|
67
|
+
console.log('默认选项配置成功:', typeof options);
|
|
68
|
+
|
|
69
|
+
// 测试HTTP选项配置
|
|
70
|
+
console.log('3. 测试HTTP选项配置...');
|
|
71
|
+
const httpOptions = http.httpOptions({
|
|
72
|
+
method: 'GET',
|
|
73
|
+
href: 'https://httpbin.org/get'
|
|
74
|
+
});
|
|
75
|
+
console.log('HTTP选项配置成功');
|
|
76
|
+
|
|
77
|
+
console.log('✅ 高级功能测试通过');
|
|
78
|
+
return true;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error('❌ 高级功能测试失败:', err.message);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
193
84
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
85
|
+
/**
|
|
86
|
+
* 错误处理测试
|
|
87
|
+
*/
|
|
88
|
+
async function testErrorHandling() {
|
|
89
|
+
console.log('\n=== 错误处理测试 ===');
|
|
90
|
+
|
|
91
|
+
const http = new Http();
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
// 测试不存在的域名
|
|
95
|
+
console.log('1. 测试不存在的域名...');
|
|
96
|
+
try {
|
|
97
|
+
// 设置较短的超时时间,避免长时间等待
|
|
98
|
+
const timeoutHttp = new Http();
|
|
99
|
+
// 使用不存在的域名进行测试
|
|
100
|
+
await timeoutHttp.get('http://nonexistent-domain-12345.test');
|
|
101
|
+
console.log('⚠️ 不存在的域名测试 - 请求可能被重定向或超时');
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.log('不存在的域名处理正确:', err.message);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 测试网络错误处理
|
|
107
|
+
console.log('2. 测试网络错误处理...');
|
|
108
|
+
try {
|
|
109
|
+
// 尝试访问一个无效的端口
|
|
110
|
+
await http.get('http://localhost:99999');
|
|
111
|
+
console.log('⚠️ 无效端口测试 - 请求可能被系统拒绝');
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.log('无效端口处理正确:', err.message);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log('✅ 错误处理测试通过');
|
|
117
|
+
return true;
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.error('❌ 错误处理测试失败:', err.message);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
199
123
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
124
|
+
/**
|
|
125
|
+
* 主测试函数
|
|
126
|
+
*/
|
|
127
|
+
async function runTests() {
|
|
128
|
+
console.log('开始mm_https模块测试...\n');
|
|
129
|
+
|
|
130
|
+
const results = [];
|
|
131
|
+
|
|
132
|
+
// 运行所有测试
|
|
133
|
+
results.push(await testBasicRequests());
|
|
134
|
+
results.push(await testAdvancedFeatures());
|
|
135
|
+
results.push(await testErrorHandling());
|
|
136
|
+
|
|
137
|
+
// 统计结果
|
|
138
|
+
const passed = results.filter(r => r).length;
|
|
139
|
+
const total = results.length;
|
|
140
|
+
|
|
141
|
+
console.log('\n=== 测试结果汇总 ===');
|
|
142
|
+
console.log(`通过: ${passed}/${total}`);
|
|
143
|
+
|
|
144
|
+
if (passed === total) {
|
|
145
|
+
console.log('🎉 所有测试通过!模块功能正常。');
|
|
146
|
+
process.exit(0);
|
|
147
|
+
} else {
|
|
148
|
+
console.log('⚠️ 部分测试失败,请检查模块功能。');
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
206
152
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
153
|
+
// 如果直接运行此文件,则执行测试
|
|
154
|
+
if (require.main === module) {
|
|
155
|
+
runTests().catch(err => {
|
|
156
|
+
console.error('测试执行失败:', err);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
214
160
|
|
|
215
|
-
|
|
161
|
+
module.exports = {
|
|
162
|
+
testBasicRequests,
|
|
163
|
+
testAdvancedFeatures,
|
|
164
|
+
testErrorHandling,
|
|
165
|
+
runTests
|
|
166
|
+
};
|