@e-mc/request 0.7.1 → 0.7.3
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/LICENSE +7 -0
- package/README.md +5 -3
- package/http/host/index.js +27 -27
- package/index.js +154 -148
- package/package.json +5 -5
- package/util.js +14 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2023 Sukina
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/http/host/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var _a, _b, _c, _d;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tls = require("tls");
|
|
5
|
-
const types_1 = require("
|
|
5
|
+
const types_1 = require("@e-mc/types");
|
|
6
6
|
const kProtocol = Symbol('protocol');
|
|
7
7
|
const kSecure = Symbol('secure');
|
|
8
8
|
const kHostname = Symbol('hostname');
|
|
@@ -85,15 +85,15 @@ class HttpHost {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
this[kVersion] = 1;
|
|
88
|
-
this[kVersionData].forEach(version => version[4
|
|
88
|
+
this[kVersionData].forEach(version => version[4] = 0);
|
|
89
89
|
}
|
|
90
90
|
async hasProtocol(version) {
|
|
91
91
|
if (version > 1) {
|
|
92
92
|
const data = this[kVersionData][version - 1];
|
|
93
93
|
if (!data || !this.secure) {
|
|
94
|
-
return 0
|
|
94
|
+
return 0;
|
|
95
95
|
}
|
|
96
|
-
const status = data[3
|
|
96
|
+
const status = data[3];
|
|
97
97
|
switch (status) {
|
|
98
98
|
case 0:
|
|
99
99
|
case 1:
|
|
@@ -102,19 +102,19 @@ class HttpHost {
|
|
|
102
102
|
return this._tlsConnect || (this._tlsConnect = new Promise(resolve => {
|
|
103
103
|
const alpn = 'h' + version;
|
|
104
104
|
const socket = tls.connect(+this.port, this.hostname, { ALPNProtocols: [alpn], requestCert: true, rejectUnauthorized: false }, () => {
|
|
105
|
-
resolve(data[3
|
|
105
|
+
resolve(data[3] = alpn === socket.alpnProtocol ? 1 : 0);
|
|
106
106
|
this._tlsConnect = null;
|
|
107
107
|
});
|
|
108
108
|
socket
|
|
109
109
|
.setNoDelay(false)
|
|
110
|
-
.setTimeout(10000
|
|
110
|
+
.setTimeout(10000)
|
|
111
111
|
.on('timeout', () => {
|
|
112
112
|
if (this._tlsConnect) {
|
|
113
|
-
if (this.error(version) >= 10
|
|
114
|
-
resolve(data[3
|
|
113
|
+
if (this.error(version) >= 10) {
|
|
114
|
+
resolve(data[3] = 0);
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
|
-
resolve(2
|
|
117
|
+
resolve(2);
|
|
118
118
|
}
|
|
119
119
|
this._tlsConnect = null;
|
|
120
120
|
}
|
|
@@ -122,36 +122,36 @@ class HttpHost {
|
|
|
122
122
|
})
|
|
123
123
|
.on('error', () => {
|
|
124
124
|
this.failed(version);
|
|
125
|
-
resolve(data[3
|
|
125
|
+
resolve(data[3] = 0);
|
|
126
126
|
this._tlsConnect = null;
|
|
127
127
|
})
|
|
128
128
|
.end();
|
|
129
129
|
}));
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
return 1
|
|
132
|
+
return 1;
|
|
133
133
|
}
|
|
134
134
|
success(version, status) {
|
|
135
135
|
const data = this[kVersionData][version - 1];
|
|
136
|
-
return status ? data[0
|
|
136
|
+
return status ? data[0] : ++data[0];
|
|
137
137
|
}
|
|
138
138
|
failed(version, status) {
|
|
139
139
|
const data = this[kVersionData][version - 1];
|
|
140
140
|
if (status) {
|
|
141
|
-
return data[1
|
|
141
|
+
return data[1];
|
|
142
142
|
}
|
|
143
143
|
this.clearAltSvc(version);
|
|
144
|
-
return ++data[1
|
|
144
|
+
return ++data[1];
|
|
145
145
|
}
|
|
146
146
|
error(version, status) {
|
|
147
147
|
const data = this[kVersionData][version - 1];
|
|
148
148
|
if (status) {
|
|
149
|
-
return data[2
|
|
149
|
+
return data[2];
|
|
150
150
|
}
|
|
151
|
-
if (data[4
|
|
151
|
+
if (data[4] !== 2) {
|
|
152
152
|
this.closeAltSvc(true);
|
|
153
153
|
}
|
|
154
|
-
return ++data[2
|
|
154
|
+
return ++data[2];
|
|
155
155
|
}
|
|
156
156
|
upgrade(version, altSvc) {
|
|
157
157
|
if (altSvc && this.secure) {
|
|
@@ -162,11 +162,11 @@ class HttpHost {
|
|
|
162
162
|
const data = this[kVersionData];
|
|
163
163
|
for (let i = data.length - 1; i >= version; --i) {
|
|
164
164
|
const host = data[i];
|
|
165
|
-
if (host[4
|
|
165
|
+
if (host[4] === 0) {
|
|
166
166
|
continue;
|
|
167
167
|
}
|
|
168
168
|
const increment = (flag) => {
|
|
169
|
-
host[4
|
|
169
|
+
host[4] = flag;
|
|
170
170
|
if (this[kVersion] < i + 1) {
|
|
171
171
|
this[kVersion] = i + 1;
|
|
172
172
|
return true;
|
|
@@ -192,7 +192,7 @@ class HttpHost {
|
|
|
192
192
|
addresses.push([
|
|
193
193
|
address,
|
|
194
194
|
port,
|
|
195
|
-
ma >= 2592000
|
|
195
|
+
ma >= 2592000 ? NaN : time + Math.min(ma * 1000, 2147483647),
|
|
196
196
|
i + 1,
|
|
197
197
|
match[3].includes('persist=1')
|
|
198
198
|
]);
|
|
@@ -229,7 +229,7 @@ class HttpHost {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
didAltSvc(version) {
|
|
232
|
-
return this[kVersionData][version][4
|
|
232
|
+
return this[kVersionData][version][4] !== -1;
|
|
233
233
|
}
|
|
234
234
|
nextAltSvc() {
|
|
235
235
|
const queue = this[kAltSvcQueue].shift();
|
|
@@ -279,20 +279,20 @@ class HttpHost {
|
|
|
279
279
|
this.closeAltSvc();
|
|
280
280
|
this[kAltSvcQueue] = [];
|
|
281
281
|
this[kAltSvcError] = [];
|
|
282
|
-
this[kVersionData].forEach(item => item[3
|
|
282
|
+
this[kVersionData].forEach(item => item[3] && (item[4] = -1));
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
flagAltSvc(version, value) {
|
|
286
|
-
this[kVersionData][version - 1][4
|
|
286
|
+
this[kVersionData][version - 1][4] = value;
|
|
287
287
|
}
|
|
288
288
|
reset() {
|
|
289
289
|
this.clearAltSvc();
|
|
290
290
|
this[kVersionData].forEach((item, index) => {
|
|
291
|
-
item[0
|
|
292
|
-
item[1
|
|
293
|
-
item[2
|
|
291
|
+
item[0] = 0;
|
|
292
|
+
item[1] = 0;
|
|
293
|
+
item[2] = 0;
|
|
294
294
|
if (index > 0) {
|
|
295
|
-
item[3
|
|
295
|
+
item[3] = -1;
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
}
|
package/index.js
CHANGED
|
@@ -15,11 +15,11 @@ const qs = require("querystring");
|
|
|
15
15
|
const combined = require("combined-stream");
|
|
16
16
|
const yaml = require("js-yaml");
|
|
17
17
|
const which = require("which");
|
|
18
|
-
const lib_v4_1 = require("
|
|
19
|
-
const types_1 = require("
|
|
20
|
-
const module_1 = require("
|
|
21
|
-
const host_1 = require("
|
|
22
|
-
const util_1 = require("
|
|
18
|
+
const lib_v4_1 = require("@e-mc/module/lib-v4");
|
|
19
|
+
const types_1 = require("@e-mc/types");
|
|
20
|
+
const module_1 = require("@e-mc/module");
|
|
21
|
+
const host_1 = require("@e-mc/request/http/host");
|
|
22
|
+
const util_1 = require("@e-mc/request/util");
|
|
23
23
|
const kSession = Symbol('session');
|
|
24
24
|
const kHttpVersion = Symbol('httpVersion');
|
|
25
25
|
const kIpVersion = Symbol('ipVersion');
|
|
@@ -177,7 +177,7 @@ function resetHttpHost(version) {
|
|
|
177
177
|
const host = HTTP.HOST[origin];
|
|
178
178
|
if (host.secure && host.version === 1) {
|
|
179
179
|
const failed = host.failed(2, true);
|
|
180
|
-
if (failed === 0 && host.failed(2, true) < 10
|
|
180
|
+
if (failed === 0 && host.failed(2, true) < 10 || failed < 3 && host.success(2, true) > 0) {
|
|
181
181
|
host.version = version;
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -272,7 +272,7 @@ class Request extends module_1.default {
|
|
|
272
272
|
return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
|
|
273
273
|
}
|
|
274
274
|
static loadSettings(settings, password) {
|
|
275
|
-
if (!this.enabled("process.password"
|
|
275
|
+
if (!this.enabled("process.password") || super.loadSettings({ process: settings.process }, password)) {
|
|
276
276
|
const { request, download } = settings;
|
|
277
277
|
if (download && (0, types_1.isPlainObject)(download.aria2)) {
|
|
278
278
|
let { bin, exec, update_status, max_concurrent_downloads, max_connection_per_server, bt_stop_timeout, bt_tracker_connect_timeout, bt_tracker_timeout, min_split_size, disk_cache, lowest_speed_limit, always_resume, file_allocation, conf_path } = download.aria2;
|
|
@@ -397,9 +397,9 @@ class Request extends module_1.default {
|
|
|
397
397
|
break;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
LOG_HTTP = this.hasLogType(1024
|
|
401
|
-
LOG_TIMEPROCESS = this.hasLogType(256
|
|
402
|
-
LOG_STDOUT = module_1.default.hasLogType(32768
|
|
400
|
+
LOG_HTTP = this.hasLogType(1024);
|
|
401
|
+
LOG_TIMEPROCESS = this.hasLogType(256);
|
|
402
|
+
LOG_STDOUT = module_1.default.hasLogType(32768);
|
|
403
403
|
return true;
|
|
404
404
|
}
|
|
405
405
|
return false;
|
|
@@ -414,151 +414,151 @@ class Request extends module_1.default {
|
|
|
414
414
|
return this.readCACert(value, cache);
|
|
415
415
|
}
|
|
416
416
|
static isCert(value) {
|
|
417
|
-
return (0, types_1.isString)(value) && (value = value.trim()) ? value.
|
|
417
|
+
return (0, types_1.isString)(value) && (value = value.trim()) ? value.includes('\n') && value.startsWith('---') && value.endsWith('---') : false;
|
|
418
418
|
}
|
|
419
419
|
static fromURL(url, value) {
|
|
420
420
|
if (this.isURL(value)) {
|
|
421
421
|
return value;
|
|
422
422
|
}
|
|
423
423
|
const auth = host_1.default.formatBasicAuth(url);
|
|
424
|
-
return url.protocol + '//' + (auth && (auth + '@')) + url.hostname + (url.port ? ':' + url.port : '') + (value
|
|
424
|
+
return url.protocol + '//' + (auth && (auth + '@')) + url.hostname + (url.port ? ':' + url.port : '') + (!value.startsWith('/') ? '/' : '') + value;
|
|
425
425
|
}
|
|
426
426
|
static fromStatusCode(value) {
|
|
427
427
|
if ((value = +value) < 200) {
|
|
428
428
|
switch (value) {
|
|
429
|
-
case 100
|
|
429
|
+
case 100:
|
|
430
430
|
return 'Continue';
|
|
431
|
-
case 101
|
|
431
|
+
case 101:
|
|
432
432
|
return 'Switching Protocol';
|
|
433
|
-
case 102
|
|
433
|
+
case 102:
|
|
434
434
|
return 'Processing';
|
|
435
|
-
case 103
|
|
435
|
+
case 103:
|
|
436
436
|
return 'Early Hints';
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
else if (value < 300) {
|
|
440
440
|
switch (value) {
|
|
441
|
-
case 200
|
|
441
|
+
case 200:
|
|
442
442
|
return 'OK';
|
|
443
|
-
case 201
|
|
443
|
+
case 201:
|
|
444
444
|
return 'Created';
|
|
445
|
-
case 202
|
|
445
|
+
case 202:
|
|
446
446
|
return 'Accepted';
|
|
447
|
-
case 203
|
|
447
|
+
case 203:
|
|
448
448
|
return 'Non-Authoritative Information';
|
|
449
|
-
case 204
|
|
449
|
+
case 204:
|
|
450
450
|
return 'No Content';
|
|
451
|
-
case 205
|
|
451
|
+
case 205:
|
|
452
452
|
return 'Reset Content';
|
|
453
|
-
case 206
|
|
453
|
+
case 206:
|
|
454
454
|
return 'Partial Content';
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
else if (value < 400) {
|
|
458
458
|
switch (value) {
|
|
459
|
-
case 300
|
|
459
|
+
case 300:
|
|
460
460
|
return 'Multiple Choice';
|
|
461
|
-
case 301
|
|
461
|
+
case 301:
|
|
462
462
|
return 'Moved Permanently';
|
|
463
|
-
case 302
|
|
463
|
+
case 302:
|
|
464
464
|
return 'Found';
|
|
465
|
-
case 303
|
|
465
|
+
case 303:
|
|
466
466
|
return 'See Other';
|
|
467
|
-
case 304
|
|
467
|
+
case 304:
|
|
468
468
|
return 'Not Modified';
|
|
469
|
-
case 305
|
|
469
|
+
case 305:
|
|
470
470
|
return 'Use Proxy';
|
|
471
|
-
case 307
|
|
471
|
+
case 307:
|
|
472
472
|
return 'Temporary Redirect';
|
|
473
|
-
case 308
|
|
473
|
+
case 308:
|
|
474
474
|
return 'Permanent Redirect';
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
else if (value < 500) {
|
|
478
478
|
switch (value) {
|
|
479
|
-
case 400
|
|
479
|
+
case 400:
|
|
480
480
|
return 'Bad Request';
|
|
481
|
-
case 401
|
|
481
|
+
case 401:
|
|
482
482
|
return 'Upgrade Required';
|
|
483
|
-
case 402
|
|
483
|
+
case 402:
|
|
484
484
|
return 'Payment Required';
|
|
485
|
-
case 403
|
|
485
|
+
case 403:
|
|
486
486
|
return 'Forbidden';
|
|
487
|
-
case 404
|
|
487
|
+
case 404:
|
|
488
488
|
return 'Not Found';
|
|
489
|
-
case 405
|
|
489
|
+
case 405:
|
|
490
490
|
return 'Method Not Allowed';
|
|
491
|
-
case 406
|
|
491
|
+
case 406:
|
|
492
492
|
return 'Not Acceptable';
|
|
493
|
-
case 407
|
|
493
|
+
case 407:
|
|
494
494
|
return 'Proxy Authentication Required';
|
|
495
|
-
case 408
|
|
495
|
+
case 408:
|
|
496
496
|
return 'Request Timeout';
|
|
497
|
-
case 409
|
|
497
|
+
case 409:
|
|
498
498
|
return 'Conflict';
|
|
499
|
-
case 410
|
|
499
|
+
case 410:
|
|
500
500
|
return 'Gone';
|
|
501
|
-
case 411
|
|
501
|
+
case 411:
|
|
502
502
|
return 'Length Required';
|
|
503
|
-
case 412
|
|
503
|
+
case 412:
|
|
504
504
|
return 'Precondition Failed';
|
|
505
|
-
case 413
|
|
505
|
+
case 413:
|
|
506
506
|
return 'Payload Too Large';
|
|
507
|
-
case 414
|
|
507
|
+
case 414:
|
|
508
508
|
return 'URI Too Long';
|
|
509
|
-
case 415
|
|
509
|
+
case 415:
|
|
510
510
|
return 'Unsupported Media Type';
|
|
511
|
-
case 416
|
|
511
|
+
case 416:
|
|
512
512
|
return 'Range Not Satisfiable';
|
|
513
|
-
case 417
|
|
513
|
+
case 417:
|
|
514
514
|
return 'Expectation Failed';
|
|
515
|
-
case 421
|
|
515
|
+
case 421:
|
|
516
516
|
return 'Misdirected Request';
|
|
517
|
-
case 422
|
|
517
|
+
case 422:
|
|
518
518
|
return 'Unprocessable Entity';
|
|
519
|
-
case 423
|
|
519
|
+
case 423:
|
|
520
520
|
return 'Locked';
|
|
521
|
-
case 424
|
|
521
|
+
case 424:
|
|
522
522
|
return 'Failed Dependency';
|
|
523
|
-
case 426
|
|
523
|
+
case 426:
|
|
524
524
|
return 'Upgrade Required';
|
|
525
|
-
case 428
|
|
525
|
+
case 428:
|
|
526
526
|
return 'Precondition Required';
|
|
527
|
-
case 429
|
|
527
|
+
case 429:
|
|
528
528
|
return 'Too Many Requests';
|
|
529
|
-
case 431
|
|
529
|
+
case 431:
|
|
530
530
|
return 'Request Header Fields Too Large';
|
|
531
|
-
case 451
|
|
531
|
+
case 451:
|
|
532
532
|
return 'Unavailable For Legal Reasons';
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
else {
|
|
536
536
|
switch (value) {
|
|
537
|
-
case 500
|
|
537
|
+
case 500:
|
|
538
538
|
return 'Internal Server Error';
|
|
539
|
-
case 501
|
|
539
|
+
case 501:
|
|
540
540
|
return 'Not Implemented';
|
|
541
|
-
case 502
|
|
541
|
+
case 502:
|
|
542
542
|
return 'Bad Gateway';
|
|
543
|
-
case 503
|
|
543
|
+
case 503:
|
|
544
544
|
return 'Service Unavailable';
|
|
545
|
-
case 504
|
|
545
|
+
case 504:
|
|
546
546
|
return 'Gateway Timeout';
|
|
547
|
-
case 505
|
|
547
|
+
case 505:
|
|
548
548
|
return 'HTTP Version Not Supported';
|
|
549
|
-
case 506
|
|
549
|
+
case 506:
|
|
550
550
|
return 'Variant Also Negotiates';
|
|
551
|
-
case 507
|
|
551
|
+
case 507:
|
|
552
552
|
return 'Insufficient Storage';
|
|
553
|
-
case 508
|
|
553
|
+
case 508:
|
|
554
554
|
return 'Loop Detected';
|
|
555
|
-
case 510
|
|
555
|
+
case 510:
|
|
556
556
|
return 'Not Extended';
|
|
557
|
-
case 511
|
|
557
|
+
case 511:
|
|
558
558
|
return 'Network Authentication Required';
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
|
-
return "Unknown"
|
|
561
|
+
return "Unknown";
|
|
562
562
|
}
|
|
563
563
|
static defineHttpAgent(options) {
|
|
564
564
|
const { keepAlive, timeout = 0 } = options;
|
|
@@ -615,13 +615,14 @@ class Request extends module_1.default {
|
|
|
615
615
|
this.startTime = Date.now();
|
|
616
616
|
this.readExpect = 'none';
|
|
617
617
|
this.proxy = null;
|
|
618
|
-
this._moduleName = "request"
|
|
618
|
+
this._moduleName = "request";
|
|
619
|
+
this._threadable = true;
|
|
619
620
|
this._config = {
|
|
620
|
-
timeout: 60000
|
|
621
|
-
connectTimeout: 20 * 1000
|
|
621
|
+
timeout: 60000,
|
|
622
|
+
connectTimeout: 20 * 1000,
|
|
622
623
|
redirectLimit: 10,
|
|
623
|
-
retryWait: 1000
|
|
624
|
-
retryAfter: 30 * 1000
|
|
624
|
+
retryWait: 1000,
|
|
625
|
+
retryAfter: 30 * 1000,
|
|
625
626
|
retryLimit: 5
|
|
626
627
|
};
|
|
627
628
|
this[_a] = false;
|
|
@@ -702,7 +703,7 @@ class Request extends module_1.default {
|
|
|
702
703
|
const args = [];
|
|
703
704
|
for (let i = 0; i < log.length; ++i) {
|
|
704
705
|
const item = log[i];
|
|
705
|
-
if (Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
|
|
706
|
+
if (item[1] === title && Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
|
|
706
707
|
item[1] = '';
|
|
707
708
|
item[2][0] = item[2][0].substring(origin.length);
|
|
708
709
|
item[4].titleBgColor = undefined;
|
|
@@ -711,12 +712,17 @@ class Request extends module_1.default {
|
|
|
711
712
|
log.splice(i--, 1);
|
|
712
713
|
}
|
|
713
714
|
}
|
|
714
|
-
output.push([title, origin, value, args]);
|
|
715
|
+
output.push([title, origin, value, args.sort((a, b) => a[2][0] < b[2][0] ? -1 : 1)]);
|
|
715
716
|
count = Math.max(count, value);
|
|
716
717
|
}
|
|
717
718
|
});
|
|
718
719
|
if (LOG_STDOUT) {
|
|
719
|
-
output.sort((a, b) =>
|
|
720
|
+
output.sort((a, b) => {
|
|
721
|
+
if (a[2] === b[2]) {
|
|
722
|
+
return a[1] < b[1] ? -1 : 1;
|
|
723
|
+
}
|
|
724
|
+
return b[2] - a[2];
|
|
725
|
+
});
|
|
720
726
|
const width = count.toString().length;
|
|
721
727
|
output.forEach(item => {
|
|
722
728
|
const [title, origin, downloads, messages] = item;
|
|
@@ -729,7 +735,7 @@ class Request extends module_1.default {
|
|
|
729
735
|
module_1.default.formatMessage(...message);
|
|
730
736
|
}
|
|
731
737
|
else {
|
|
732
|
-
this.formatMessage(1024
|
|
738
|
+
this.formatMessage(1024, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
|
|
733
739
|
messages.forEach(args => {
|
|
734
740
|
args[4].titleIndent = true;
|
|
735
741
|
module_1.default.formatMessage(...args);
|
|
@@ -759,7 +765,7 @@ class Request extends module_1.default {
|
|
|
759
765
|
}
|
|
760
766
|
init(config) {
|
|
761
767
|
if (config) {
|
|
762
|
-
const { headers, httpVersion, ipVersion, requestTimeout } = config;
|
|
768
|
+
const { headers, httpVersion, ipVersion, requestTimeout, readTimeout = requestTimeout } = config;
|
|
763
769
|
if ((0, types_1.isObject)(headers)) {
|
|
764
770
|
setOutgoingHeaders(this[kHeaders] || (this[kHeaders] = {}), headers);
|
|
765
771
|
}
|
|
@@ -769,8 +775,8 @@ class Request extends module_1.default {
|
|
|
769
775
|
if (ipVersion !== undefined) {
|
|
770
776
|
this.ipVersion = ipVersion;
|
|
771
777
|
}
|
|
772
|
-
if (
|
|
773
|
-
this.readTimeout = (0, util_1.fromSeconds)(
|
|
778
|
+
if (readTimeout !== undefined) {
|
|
779
|
+
this.readTimeout = (0, util_1.fromSeconds)(readTimeout);
|
|
774
780
|
}
|
|
775
781
|
}
|
|
776
782
|
return this;
|
|
@@ -791,7 +797,7 @@ class Request extends module_1.default {
|
|
|
791
797
|
this._config.redirectLimit = redirectLimit;
|
|
792
798
|
}
|
|
793
799
|
if (retryWait >= 0) {
|
|
794
|
-
this._config.retryWait = Math.min(retryWait, 600 * 1000
|
|
800
|
+
this._config.retryWait = Math.min(retryWait, 600 * 1000);
|
|
795
801
|
}
|
|
796
802
|
if (retryAfter >= 0) {
|
|
797
803
|
this._config.retryAfter = Math.min(retryAfter, module_1.default.MAX_TIMEOUT);
|
|
@@ -930,9 +936,9 @@ class Request extends module_1.default {
|
|
|
930
936
|
const headers = this[kHeaders];
|
|
931
937
|
return headers && getBaseHeaders(uri, headers) || (this.host ? getBaseHeaders(uri, HTTP.HEADERS) : undefined);
|
|
932
938
|
}
|
|
933
|
-
aria2c(uri, options) {
|
|
939
|
+
async aria2c(uri, options) {
|
|
934
940
|
if (!ARIA2.BIN) {
|
|
935
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
941
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Binary not found"));
|
|
936
942
|
}
|
|
937
943
|
if (typeof uri === 'string' && module_1.default.isURL(uri)) {
|
|
938
944
|
try {
|
|
@@ -1000,15 +1006,15 @@ class Request extends module_1.default {
|
|
|
1000
1006
|
}
|
|
1001
1007
|
if (!(0, types_1.isString)(pathname)) {
|
|
1002
1008
|
if (this.host) {
|
|
1003
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1009
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Invalid parameters", 'pathname'));
|
|
1004
1010
|
}
|
|
1005
1011
|
pathname = process.cwd();
|
|
1006
1012
|
}
|
|
1007
1013
|
if ((this.host || this.hasOwnPermission()) && !this.canWrite(pathname = path.resolve(pathname.trim()))) {
|
|
1008
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1014
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Unsupported access", pathname));
|
|
1009
1015
|
}
|
|
1010
1016
|
if (!module_1.default.createDir(pathname)) {
|
|
1011
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1017
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
|
|
1012
1018
|
}
|
|
1013
1019
|
silent ?? (silent = this[kSingleton]);
|
|
1014
1020
|
return new Promise((resolve, reject) => {
|
|
@@ -1173,11 +1179,11 @@ class Request extends module_1.default {
|
|
|
1173
1179
|
args = binOpts.concat(args);
|
|
1174
1180
|
}
|
|
1175
1181
|
if (args.length) {
|
|
1176
|
-
if (module_1.default.hasLogType(32768
|
|
1177
|
-
this.formatMessage(32768
|
|
1182
|
+
if (module_1.default.hasLogType(32768)) {
|
|
1183
|
+
this.formatMessage(32768, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
|
|
1178
1184
|
}
|
|
1179
1185
|
else {
|
|
1180
|
-
this.addLog(types_1.STATUS_TYPE.INFO, path.basename(ARIA2.BIN) + ' ' + args.join(' '), "aria2"
|
|
1186
|
+
this.addLog(types_1.STATUS_TYPE.INFO, path.basename(ARIA2.BIN) + ' ' + args.join(' '), "aria2");
|
|
1181
1187
|
}
|
|
1182
1188
|
}
|
|
1183
1189
|
opts.push(`"${escapeQuote(uri)}"`);
|
|
@@ -1221,18 +1227,18 @@ class Request extends module_1.default {
|
|
|
1221
1227
|
break;
|
|
1222
1228
|
}
|
|
1223
1229
|
case 'ERR':
|
|
1224
|
-
fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file"
|
|
1230
|
+
fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file", path.basename(file)], err, { type: 32, fatal: false }));
|
|
1225
1231
|
break;
|
|
1226
1232
|
}
|
|
1227
1233
|
}
|
|
1228
1234
|
if (result.length && !silent && LOG_HTTP && LOG_TIMEPROCESS) {
|
|
1229
|
-
this.writeTimeProcess("aria2"
|
|
1235
|
+
this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
|
|
1230
1236
|
}
|
|
1231
|
-
this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2"
|
|
1237
|
+
this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2", uri);
|
|
1232
1238
|
resolve(result);
|
|
1233
1239
|
}
|
|
1234
1240
|
else {
|
|
1235
|
-
reject((0, types_1.errorValue)(message || "Unknown"
|
|
1241
|
+
reject((0, types_1.errorValue)(message || "Unknown", 'Exit status: ' + code));
|
|
1236
1242
|
}
|
|
1237
1243
|
})
|
|
1238
1244
|
.on('error', err => errorResponse(pid, err));
|
|
@@ -1268,9 +1274,9 @@ class Request extends module_1.default {
|
|
|
1268
1274
|
}
|
|
1269
1275
|
else {
|
|
1270
1276
|
const current = (0, types_1.getLogCurrent)();
|
|
1271
|
-
progressBar = current?.type === 128
|
|
1277
|
+
progressBar = current?.type === 128 && current.title === "aria2";
|
|
1272
1278
|
}
|
|
1273
|
-
this.formatMessage(128
|
|
1279
|
+
this.formatMessage(128, "aria2", ['Downloading...', (0, types_1.formatTime)(startTime, true)], (PLATFORM_WIN32 ? 'taskkill /f /pid' : 'kill') + ` ${item[0]} -> ` + item[1], { ...module_1.default.LOG_STYLE_INFO, progressBar, broadcastId });
|
|
1274
1280
|
}
|
|
1275
1281
|
ARIA2.PID_QUEUE.push(item);
|
|
1276
1282
|
}
|
|
@@ -1278,17 +1284,17 @@ class Request extends module_1.default {
|
|
|
1278
1284
|
clearTimer();
|
|
1279
1285
|
}
|
|
1280
1286
|
}
|
|
1281
|
-
}, (ARIA2.UPDATE_STATUS || 30) * 1000
|
|
1287
|
+
}, (ARIA2.UPDATE_STATUS || 30) * 1000);
|
|
1282
1288
|
}
|
|
1283
1289
|
ARIA2.PID_QUEUE.push([pid, uri, this.broadcastId || undefined]);
|
|
1284
1290
|
}
|
|
1285
1291
|
});
|
|
1286
1292
|
}
|
|
1287
|
-
json(uri, options = {}) {
|
|
1293
|
+
async json(uri, options = {}) {
|
|
1288
1294
|
options.format = 'json';
|
|
1289
1295
|
return this.get(uri, options);
|
|
1290
1296
|
}
|
|
1291
|
-
pipe(uri, to, options = {}) {
|
|
1297
|
+
async pipe(uri, to, options = {}) {
|
|
1292
1298
|
options.pipeTo = to;
|
|
1293
1299
|
return this.get(uri, options);
|
|
1294
1300
|
}
|
|
@@ -1357,9 +1363,9 @@ class Request extends module_1.default {
|
|
|
1357
1363
|
}
|
|
1358
1364
|
const checkEncoding = (response, statusCode, contentEncoding = '') => {
|
|
1359
1365
|
switch (statusCode) {
|
|
1360
|
-
case 206
|
|
1366
|
+
case 206:
|
|
1361
1367
|
request.emit('error', new Error('[ABORT] Partial content'));
|
|
1362
|
-
case 204
|
|
1368
|
+
case 204:
|
|
1363
1369
|
return;
|
|
1364
1370
|
}
|
|
1365
1371
|
const chunkSize = outStream?.writableHighWaterMark;
|
|
@@ -1408,7 +1414,7 @@ class Request extends module_1.default {
|
|
|
1408
1414
|
}
|
|
1409
1415
|
}
|
|
1410
1416
|
if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
|
|
1411
|
-
request = ((_m = this[kSession][0])[origin] || (_m[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? {
|
|
1417
|
+
request = ((_m = this[kSession][0])[origin] || (_m[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
|
|
1412
1418
|
if (getting) {
|
|
1413
1419
|
const listenerMap = {};
|
|
1414
1420
|
const onEvent = request.on.bind(request);
|
|
@@ -1417,7 +1423,7 @@ class Request extends module_1.default {
|
|
|
1417
1423
|
request.on('response', response => {
|
|
1418
1424
|
connected = true;
|
|
1419
1425
|
const statusCode = response[':status'];
|
|
1420
|
-
if (statusCode >= 200
|
|
1426
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
1421
1427
|
if (emitter = checkEncoding(request, statusCode, response['content-encoding'])) {
|
|
1422
1428
|
for (const event in listenerMap) {
|
|
1423
1429
|
listenerMap[event].forEach(listener => {
|
|
@@ -1500,7 +1506,7 @@ class Request extends module_1.default {
|
|
|
1500
1506
|
}
|
|
1501
1507
|
}
|
|
1502
1508
|
catch (err) {
|
|
1503
|
-
this.checkPackage(err, pkg, "Unknown"
|
|
1509
|
+
this.checkPackage(err, pkg, "Unknown");
|
|
1504
1510
|
}
|
|
1505
1511
|
}
|
|
1506
1512
|
else if (keepAlive === false) {
|
|
@@ -1536,7 +1542,7 @@ class Request extends module_1.default {
|
|
|
1536
1542
|
agent
|
|
1537
1543
|
}, response => {
|
|
1538
1544
|
const statusCode = response.statusCode;
|
|
1539
|
-
if ((getting || posting) && statusCode >= 200
|
|
1545
|
+
if ((getting || posting) && statusCode >= 200 && statusCode < 300) {
|
|
1540
1546
|
const incoming = response.headers;
|
|
1541
1547
|
let source = checkEncoding(response, statusCode, incoming['content-encoding']);
|
|
1542
1548
|
if (source) {
|
|
@@ -1630,7 +1636,7 @@ class Request extends module_1.default {
|
|
|
1630
1636
|
options = contentType;
|
|
1631
1637
|
contentType = undefined;
|
|
1632
1638
|
}
|
|
1633
|
-
if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data"
|
|
1639
|
+
if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data")) {
|
|
1634
1640
|
parts = data;
|
|
1635
1641
|
data = undefined;
|
|
1636
1642
|
}
|
|
@@ -1656,23 +1662,23 @@ class Request extends module_1.default {
|
|
|
1656
1662
|
delete headers[attr];
|
|
1657
1663
|
}
|
|
1658
1664
|
}
|
|
1659
|
-
if (parts || contentType === "multipart/form-data"
|
|
1665
|
+
if (parts || contentType === "multipart/form-data" || contentType === 'form-data') {
|
|
1660
1666
|
let valid;
|
|
1661
1667
|
if ((0, types_1.isArray)(parts)) {
|
|
1662
1668
|
const write = combined.create();
|
|
1663
1669
|
const boundary = (0, types_1.generateUUID)().replace(/-/g, '');
|
|
1664
|
-
contentType = "multipart/form-data"
|
|
1670
|
+
contentType = "multipart/form-data" + `; boundary="${boundary}"`;
|
|
1665
1671
|
let contentLength = 0;
|
|
1666
1672
|
const createPart = (name, filename, type) => {
|
|
1667
|
-
const form = ["--"
|
|
1673
|
+
const form = ["--" + boundary, `Content-Disposition: form-data; name="${escapeQuote(name)}"` + (filename ? `; filename="${escapeQuote(filename)}"` : ''), "\r\n"];
|
|
1668
1674
|
if (type) {
|
|
1669
1675
|
form.splice(2, 0, 'Content-Type: ' + type);
|
|
1670
1676
|
}
|
|
1671
|
-
return form.join("\r\n"
|
|
1677
|
+
return form.join("\r\n");
|
|
1672
1678
|
};
|
|
1673
1679
|
const addValue = (name, value) => {
|
|
1674
1680
|
if (value !== undefined) {
|
|
1675
|
-
const disposition = createPart(name) + module_1.default.asString(value) + "\r\n"
|
|
1681
|
+
const disposition = createPart(name) + module_1.default.asString(value) + "\r\n";
|
|
1676
1682
|
write.append(disposition);
|
|
1677
1683
|
contentLength += Buffer.byteLength(disposition);
|
|
1678
1684
|
}
|
|
@@ -1702,7 +1708,7 @@ class Request extends module_1.default {
|
|
|
1702
1708
|
target = Buffer.concat(chunks);
|
|
1703
1709
|
}
|
|
1704
1710
|
if (!Buffer.isBuffer(target)) {
|
|
1705
|
-
throw (0, types_1.errorMessage)('File', "Unknown"
|
|
1711
|
+
throw (0, types_1.errorMessage)('File', "Unknown", "multipart/form-data");
|
|
1706
1712
|
}
|
|
1707
1713
|
if (!type || !filename) {
|
|
1708
1714
|
const result = await module_1.default.resolveMime(target);
|
|
@@ -1718,11 +1724,11 @@ class Request extends module_1.default {
|
|
|
1718
1724
|
filename = (0, types_1.generateUUID)() + '.' + ext;
|
|
1719
1725
|
}
|
|
1720
1726
|
}
|
|
1721
|
-
const disposition = createPart(name, filename, type || "application/octet-stream"
|
|
1727
|
+
const disposition = createPart(name, filename, type || "application/octet-stream");
|
|
1722
1728
|
write.append(disposition);
|
|
1723
1729
|
write.append(target);
|
|
1724
|
-
write.append("\r\n"
|
|
1725
|
-
contentLength += Buffer.byteLength(disposition) + target.length + 2
|
|
1730
|
+
write.append("\r\n");
|
|
1731
|
+
contentLength += Buffer.byteLength(disposition) + target.length + 2;
|
|
1726
1732
|
valid = true;
|
|
1727
1733
|
}
|
|
1728
1734
|
catch (err) {
|
|
@@ -1734,13 +1740,13 @@ class Request extends module_1.default {
|
|
|
1734
1740
|
}
|
|
1735
1741
|
}
|
|
1736
1742
|
if (valid) {
|
|
1737
|
-
write.append("--"
|
|
1738
|
-
headers['content-length'] = (contentLength + 38
|
|
1743
|
+
write.append("--" + boundary + "--" + "\r\n");
|
|
1744
|
+
headers['content-length'] = (contentLength + 38).toString();
|
|
1739
1745
|
data = write;
|
|
1740
1746
|
}
|
|
1741
1747
|
}
|
|
1742
1748
|
if (!valid) {
|
|
1743
|
-
return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data"
|
|
1749
|
+
return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data"));
|
|
1744
1750
|
}
|
|
1745
1751
|
}
|
|
1746
1752
|
else {
|
|
@@ -1750,22 +1756,22 @@ class Request extends module_1.default {
|
|
|
1750
1756
|
if (!(0, types_1.isPlainObject)(data)) {
|
|
1751
1757
|
data = module_1.default.asString(data);
|
|
1752
1758
|
}
|
|
1753
|
-
else if (contentType === "application/x-www-form-urlencoded"
|
|
1759
|
+
else if (contentType === "application/x-www-form-urlencoded") {
|
|
1754
1760
|
data = qs.stringify(data);
|
|
1755
1761
|
}
|
|
1756
1762
|
else {
|
|
1757
1763
|
data = JSON.stringify(data);
|
|
1758
|
-
contentType || (contentType = "application/json"
|
|
1764
|
+
contentType || (contentType = "application/json");
|
|
1759
1765
|
}
|
|
1760
1766
|
headers['content-length'] = Buffer.byteLength(data, (0, types_1.getEncoding)(dataEncoding)).toString();
|
|
1761
1767
|
}
|
|
1762
1768
|
options.method = 'POST';
|
|
1763
1769
|
options.httpVersion = 1;
|
|
1764
1770
|
options.postData = data;
|
|
1765
|
-
headers['content-type'] = contentType || "text/plain"
|
|
1771
|
+
headers['content-type'] = contentType || "text/plain";
|
|
1766
1772
|
return this.get(uri, options);
|
|
1767
1773
|
}
|
|
1768
|
-
get(uri, options = {}) {
|
|
1774
|
+
async get(uri, options = {}) {
|
|
1769
1775
|
const opts = (typeof options === 'string' ? { format: options, encoding: 'utf-8' } : options);
|
|
1770
1776
|
if (this.readExpect === 'string') {
|
|
1771
1777
|
opts.encoding = (0, types_1.getEncoding)(opts?.encoding);
|
|
@@ -1800,7 +1806,7 @@ class Request extends module_1.default {
|
|
|
1800
1806
|
}
|
|
1801
1807
|
if (pipeTo) {
|
|
1802
1808
|
if ((0, types_1.isString)(pipeTo)) {
|
|
1803
|
-
outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536
|
|
1809
|
+
outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536 : 4096 });
|
|
1804
1810
|
request.outStream = outStream;
|
|
1805
1811
|
}
|
|
1806
1812
|
else {
|
|
@@ -1816,9 +1822,9 @@ class Request extends module_1.default {
|
|
|
1816
1822
|
({ httpVersion, outAbort } = request);
|
|
1817
1823
|
const isAborted = () => client.destroyed || httpVersion === 2 && client.aborted;
|
|
1818
1824
|
const isRetry = (value) => (0, util_1.isRetryable)(value) && ++retries <= this._config.retryLimit;
|
|
1819
|
-
const isUnsupported = (value) => value === 421
|
|
1825
|
+
const isUnsupported = (value) => value === 421 || value === 505;
|
|
1820
1826
|
const isDowngrade = (err) => err instanceof Error && (err.code === 'ERR_HTTP2_ERROR' || isUnsupported(Math.abs(err.errno)));
|
|
1821
|
-
const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024
|
|
1827
|
+
const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { titleBgColor: 'bgGrey', titleColor: 'yellow' });
|
|
1822
1828
|
const formatNgFlags = (value, statusCode, location) => location ? `Using HTTP 1.1 for URL redirect (${location})` : formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
|
|
1823
1829
|
const abortResponse = () => {
|
|
1824
1830
|
if (closed) {
|
|
@@ -1858,7 +1864,7 @@ class Request extends module_1.default {
|
|
|
1858
1864
|
if (readTimeout > 0) {
|
|
1859
1865
|
timeout = setTimeout(() => {
|
|
1860
1866
|
abortResponse();
|
|
1861
|
-
throwError((0, types_1.errorValue)("Timeout was exceeded"
|
|
1867
|
+
throwError((0, types_1.errorValue)("Timeout was exceeded", href.toString()));
|
|
1862
1868
|
}, readTimeout);
|
|
1863
1869
|
}
|
|
1864
1870
|
if (log) {
|
|
@@ -1918,19 +1924,19 @@ class Request extends module_1.default {
|
|
|
1918
1924
|
}
|
|
1919
1925
|
}
|
|
1920
1926
|
if (mibsTime) {
|
|
1921
|
-
const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000
|
|
1927
|
+
const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000);
|
|
1922
1928
|
if (unit < 1) {
|
|
1923
|
-
messageUnit = Math.ceil(unit * 1000
|
|
1929
|
+
messageUnit = Math.ceil(unit * 1000) + 'KiB/s';
|
|
1924
1930
|
}
|
|
1925
|
-
else if (unit < 1000
|
|
1931
|
+
else if (unit < 1000) {
|
|
1926
1932
|
messageUnit = unit.toPrecision(3) + 'MiB/s';
|
|
1927
1933
|
}
|
|
1928
1934
|
else {
|
|
1929
|
-
messageUnit = (unit / 1000
|
|
1935
|
+
messageUnit = (unit / 1000).toPrecision(3) + 'GiB/s';
|
|
1930
1936
|
}
|
|
1931
1937
|
}
|
|
1932
1938
|
if (typeof buffer === 'string') {
|
|
1933
|
-
if (buffer
|
|
1939
|
+
if (buffer.startsWith('\uFEFF') && encoding !== 'utf16le') {
|
|
1934
1940
|
buffer = buffer.substring(1);
|
|
1935
1941
|
}
|
|
1936
1942
|
if (outFormat) {
|
|
@@ -1960,7 +1966,7 @@ class Request extends module_1.default {
|
|
|
1960
1966
|
}
|
|
1961
1967
|
catch (err) {
|
|
1962
1968
|
if (!silent && !this[kSingleton] && !(packageName && this.checkPackage(err, packageName))) {
|
|
1963
|
-
this.writeFail(['Unable to parse URI response', format], err, 1024
|
|
1969
|
+
this.writeFail(['Unable to parse URI response', format], err, 1024);
|
|
1964
1970
|
}
|
|
1965
1971
|
result = null;
|
|
1966
1972
|
}
|
|
@@ -1980,7 +1986,7 @@ class Request extends module_1.default {
|
|
|
1980
1986
|
}
|
|
1981
1987
|
resolve(result);
|
|
1982
1988
|
if (log) {
|
|
1983
|
-
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024
|
|
1989
|
+
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: LOG_STDOUT });
|
|
1984
1990
|
}
|
|
1985
1991
|
});
|
|
1986
1992
|
host.success(httpVersion);
|
|
@@ -2055,7 +2061,7 @@ class Request extends module_1.default {
|
|
|
2055
2061
|
host.failed(2);
|
|
2056
2062
|
if (host.version > 1) {
|
|
2057
2063
|
if (!silent) {
|
|
2058
|
-
this.formatMessage(1024
|
|
2064
|
+
this.formatMessage(1024, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
|
|
2059
2065
|
}
|
|
2060
2066
|
host.version = 1;
|
|
2061
2067
|
}
|
|
@@ -2068,18 +2074,18 @@ class Request extends module_1.default {
|
|
|
2068
2074
|
return;
|
|
2069
2075
|
}
|
|
2070
2076
|
const statusCode = headers[':status'];
|
|
2071
|
-
if (statusCode < 300
|
|
2077
|
+
if (statusCode < 300) {
|
|
2072
2078
|
acceptResponse(headers);
|
|
2073
2079
|
}
|
|
2074
|
-
else if (statusCode < 400
|
|
2080
|
+
else if (statusCode < 400) {
|
|
2075
2081
|
redirectResponse(statusCode, headers.location);
|
|
2076
2082
|
}
|
|
2077
|
-
else if (statusCode === 401
|
|
2078
|
-
statusCode === 402
|
|
2079
|
-
statusCode === 403
|
|
2080
|
-
statusCode === 404
|
|
2081
|
-
statusCode === 407
|
|
2082
|
-
statusCode === 410
|
|
2083
|
+
else if (statusCode === 401 ||
|
|
2084
|
+
statusCode === 402 ||
|
|
2085
|
+
statusCode === 403 ||
|
|
2086
|
+
statusCode === 404 ||
|
|
2087
|
+
statusCode === 407 ||
|
|
2088
|
+
statusCode === 410) {
|
|
2083
2089
|
throwError(formatStatus(statusCode), outAbort);
|
|
2084
2090
|
}
|
|
2085
2091
|
else if (isRetry(statusCode)) {
|
|
@@ -2115,10 +2121,10 @@ class Request extends module_1.default {
|
|
|
2115
2121
|
return;
|
|
2116
2122
|
}
|
|
2117
2123
|
switch (!isDowngrade(err) && await host.hasProtocol(2)) {
|
|
2118
|
-
case 1
|
|
2124
|
+
case 1:
|
|
2119
2125
|
errorResponse(err);
|
|
2120
2126
|
break;
|
|
2121
|
-
case 2
|
|
2127
|
+
case 2:
|
|
2122
2128
|
retryDownload(false, err);
|
|
2123
2129
|
break;
|
|
2124
2130
|
default:
|
|
@@ -2134,10 +2140,10 @@ class Request extends module_1.default {
|
|
|
2134
2140
|
return;
|
|
2135
2141
|
}
|
|
2136
2142
|
const statusCode = res.statusCode;
|
|
2137
|
-
if (statusCode < 300
|
|
2143
|
+
if (statusCode < 300) {
|
|
2138
2144
|
acceptResponse(res.headers);
|
|
2139
2145
|
}
|
|
2140
|
-
else if (statusCode < 400
|
|
2146
|
+
else if (statusCode < 400) {
|
|
2141
2147
|
redirectResponse(statusCode, res.headers.location);
|
|
2142
2148
|
}
|
|
2143
2149
|
else if (isRetry(statusCode)) {
|
|
@@ -2167,7 +2173,7 @@ class Request extends module_1.default {
|
|
|
2167
2173
|
retryTimeout();
|
|
2168
2174
|
}
|
|
2169
2175
|
else {
|
|
2170
|
-
throwError(formatStatus(408
|
|
2176
|
+
throwError(formatStatus(408));
|
|
2171
2177
|
}
|
|
2172
2178
|
});
|
|
2173
2179
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/e-mc.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/request"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.7.
|
|
24
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/module": "0.7.3",
|
|
24
|
+
"@e-mc/types": "0.7.3",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"which": "^2.0.2"
|
package/util.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fromSeconds = exports.asFloat = exports.asInt = exports.trimPath = exports.isRetryable = exports.checkRetryable = exports.hasBasicAuth = exports.getBasicAuth = exports.normalizeHeaders = exports.parseHeader = void 0;
|
|
4
|
-
const module_1 = require("
|
|
5
|
-
const types_1 = require("
|
|
4
|
+
const module_1 = require("@e-mc/module");
|
|
5
|
+
const types_1 = require("@e-mc/types");
|
|
6
6
|
const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
|
|
7
7
|
function parseHeader(headers, name) {
|
|
8
8
|
const value = headers[name];
|
|
@@ -87,19 +87,19 @@ function checkRetryable(err) {
|
|
|
87
87
|
exports.checkRetryable = checkRetryable;
|
|
88
88
|
function isRetryable(value, timeout) {
|
|
89
89
|
switch (value) {
|
|
90
|
-
case 408
|
|
91
|
-
case 504
|
|
92
|
-
case 522
|
|
93
|
-
case 524
|
|
90
|
+
case 408:
|
|
91
|
+
case 504:
|
|
92
|
+
case 522:
|
|
93
|
+
case 524:
|
|
94
94
|
if (timeout) {
|
|
95
95
|
return true;
|
|
96
96
|
}
|
|
97
|
-
case 429
|
|
98
|
-
case 499
|
|
99
|
-
case 500
|
|
100
|
-
case 502
|
|
101
|
-
case 503
|
|
102
|
-
case 521
|
|
97
|
+
case 429:
|
|
98
|
+
case 499:
|
|
99
|
+
case 500:
|
|
100
|
+
case 502:
|
|
101
|
+
case 503:
|
|
102
|
+
case 521:
|
|
103
103
|
if (!timeout) {
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
@@ -138,9 +138,9 @@ exports.asFloat = asFloat;
|
|
|
138
138
|
function fromSeconds(value) {
|
|
139
139
|
switch (typeof value) {
|
|
140
140
|
case 'string':
|
|
141
|
-
return safeInt(
|
|
141
|
+
return safeInt(parseInt(value) * 1000);
|
|
142
142
|
case 'number':
|
|
143
|
-
return safeInt(value * 1000
|
|
143
|
+
return safeInt(Math.trunc(value) * 1000);
|
|
144
144
|
default:
|
|
145
145
|
return NaN;
|
|
146
146
|
}
|