mm_https 1.6.0 → 1.6.2
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 -53
- package/package.json +37 -37
package/index.js
CHANGED
|
@@ -44,13 +44,13 @@ class Http {
|
|
|
44
44
|
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
45
45
|
'Cache-Control': 'no-cache',
|
|
46
46
|
'Connection': 'keep-alive',
|
|
47
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
47
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
if (this.config.cookie) {
|
|
51
51
|
this.set_cookie(this.config.cookie);
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
if (this.config.headers) {
|
|
55
55
|
var headers = this.change_headers(config.headers);
|
|
56
56
|
Object.assign(this.headers, headers);
|
|
@@ -144,46 +144,6 @@ Http.prototype.http_options = function(options) {
|
|
|
144
144
|
}, u);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
// Http.prototype.http_options = function(options) {
|
|
148
|
-
// var cg = this.config;
|
|
149
|
-
// var {
|
|
150
|
-
// href,
|
|
151
|
-
// body,
|
|
152
|
-
// headers,
|
|
153
|
-
// method,
|
|
154
|
-
// cookie,
|
|
155
|
-
// type
|
|
156
|
-
// } = options;
|
|
157
|
-
// var protocol = href.left(":/") || 'http';
|
|
158
|
-
// // 移除协议头 取端口号
|
|
159
|
-
// var u = href.replace(protocol + "://", "");
|
|
160
|
-
// var port = u.between(":", "/") || u.left("/", true).right(":") || (protocol === 'http' ? 80 : 443);
|
|
161
|
-
|
|
162
|
-
// // 移除端口号,取主机地址
|
|
163
|
-
// u = u.replace(":" + port, "");
|
|
164
|
-
// var hostname = u.left("/", true).left("?", true);
|
|
165
|
-
// // 移除主机地址,取路由路径
|
|
166
|
-
// u = u.replace(hostname, "");
|
|
167
|
-
// var path = u.left("?", true);
|
|
168
|
-
// if (cookie) {
|
|
169
|
-
// this.set_cookie(cookie);
|
|
170
|
-
// }
|
|
171
|
-
// return {
|
|
172
|
-
// href,
|
|
173
|
-
// protocol,
|
|
174
|
-
// hostname,
|
|
175
|
-
// body,
|
|
176
|
-
// type,
|
|
177
|
-
// port: Number(port),
|
|
178
|
-
// search: "?" + u.right("?"),
|
|
179
|
-
// path: path.indexOf("/") === 0 ? path : "/" + path,
|
|
180
|
-
// method: method || "GET",
|
|
181
|
-
// headers: headers ? Object.assign({}, cg.headers, headers) : Object.assign({}, cg.headers),
|
|
182
|
-
// agent: cg.proxy ? new HttpProxyAgent(cg.proxy) : null,
|
|
183
|
-
// cookie: this.get_cookie()
|
|
184
|
-
// }
|
|
185
|
-
// }
|
|
186
|
-
|
|
187
147
|
Http.prototype.post_option = function(op) {
|
|
188
148
|
var param = op.body;
|
|
189
149
|
var body = "";
|
|
@@ -197,7 +157,7 @@ Http.prototype.post_option = function(op) {
|
|
|
197
157
|
} else if (type.indexOf('html') !== -1) {
|
|
198
158
|
type = "text/html; charset=UTF-8";
|
|
199
159
|
} else if (type.indexOf('form') !== -1) {
|
|
200
|
-
type = "application/x-www-form-urlencoded
|
|
160
|
+
type = "application/x-www-form-urlencoded";
|
|
201
161
|
} else {
|
|
202
162
|
type = "text/plain; charset=UTF-8";
|
|
203
163
|
}
|
|
@@ -223,7 +183,9 @@ Http.prototype.post_option = function(op) {
|
|
|
223
183
|
}
|
|
224
184
|
}
|
|
225
185
|
op.body = body;
|
|
226
|
-
op.headers['Content-Type']
|
|
186
|
+
if (!op.headers['Content-Type']) {
|
|
187
|
+
op.headers['Content-Type'] = type;
|
|
188
|
+
}
|
|
227
189
|
op.headers['Content-Length'] = Buffer.byteLength(body);
|
|
228
190
|
}
|
|
229
191
|
|
|
@@ -238,7 +200,7 @@ Http.prototype.req = async function(options) {
|
|
|
238
200
|
this.post_option(op);
|
|
239
201
|
}
|
|
240
202
|
var res = await this.request(op);
|
|
241
|
-
if (res.status.code == 302) {
|
|
203
|
+
if (res.status.code == 302 || res.status.code == 307) {
|
|
242
204
|
var url = res.headers.location;
|
|
243
205
|
var lt = res.headers['set-cookie'];
|
|
244
206
|
if (lt) {
|
|
@@ -246,14 +208,13 @@ Http.prototype.req = async function(options) {
|
|
|
246
208
|
for (var i = 0; i < len; i++) {
|
|
247
209
|
this.set_cookie(lt[i]);
|
|
248
210
|
}
|
|
249
|
-
options.href = url;
|
|
250
|
-
op = this.http_options(options);
|
|
251
|
-
op.referer = options.href;
|
|
252
|
-
res = await this.request(op);
|
|
253
211
|
}
|
|
254
|
-
|
|
255
|
-
|
|
212
|
+
options.href = url;
|
|
213
|
+
op = this.http_options(options);
|
|
214
|
+
op.referer = options.href;
|
|
215
|
+
res = await this.request(op);
|
|
256
216
|
}
|
|
217
|
+
return res;
|
|
257
218
|
}
|
|
258
219
|
|
|
259
220
|
Http.prototype.undata = function(encoding) {
|
|
@@ -324,8 +285,7 @@ Http.prototype.request = function(options) {
|
|
|
324
285
|
var mh = body.match(/charset=gb2312"/i);
|
|
325
286
|
if (mh) {
|
|
326
287
|
body = iconv.decode(buffer, 'gb2312');
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
288
|
+
} else {
|
|
329
289
|
mh = body.match(/charset=GBK"/i);
|
|
330
290
|
if (mh) {
|
|
331
291
|
body = iconv.decode(buffer, 'GBK');
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
2
|
+
"name": "mm_https",
|
|
3
|
+
"version": "1.6.2",
|
|
4
|
+
"description": "这是超级美眉http请求帮助类模块,可自动补充cookie,实现模拟登录,通讯",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test.js",
|
|
8
|
+
"dev": "nodemon test.js"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/qiuwenwu/mm_https.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"myhttp",
|
|
16
|
+
"async",
|
|
17
|
+
"await",
|
|
18
|
+
"promise",
|
|
19
|
+
"add",
|
|
20
|
+
"del",
|
|
21
|
+
"set",
|
|
22
|
+
"get",
|
|
23
|
+
"query",
|
|
24
|
+
"run",
|
|
25
|
+
"exec"
|
|
26
|
+
],
|
|
27
|
+
"author": "邱文武",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/qiuwenwu/mm_https/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/qiuwenwu/mm_https#readme",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"https-proxy-agent": "^7.0.6",
|
|
35
|
+
"iconv-lite": "^0.6.3",
|
|
36
|
+
"mm_expand": "^1.7.7"
|
|
37
|
+
}
|
|
38
|
+
}
|