@e-mc/request 0.8.4 → 0.8.6
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 +11 -0
- package/README.md +6 -6
- package/http/host/index.js +27 -27
- package/index.js +158 -158
- package/package.json +3 -3
- package/util.js +14 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -17,9 +17,9 @@ import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, Interne
|
|
|
17
17
|
import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
|
|
18
18
|
import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
|
|
19
19
|
|
|
20
|
-
import type { Writable } from "stream";
|
|
21
|
-
import type { LookupFunction } from "net";
|
|
22
20
|
import type { ClientRequest, OutgoingHttpHeaders } from "http";
|
|
21
|
+
import type { LookupFunction } from "net";
|
|
22
|
+
import type { Writable } from "stream";
|
|
23
23
|
|
|
24
24
|
interface IRequest extends IModule {
|
|
25
25
|
module: RequestModule;
|
|
@@ -82,9 +82,9 @@ interface RequestConstructor extends ModuleConstructor {
|
|
|
82
82
|
|
|
83
83
|
## References
|
|
84
84
|
|
|
85
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
86
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
87
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
85
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/http.d.ts
|
|
86
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/request.d.ts
|
|
87
|
+
- https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
|
|
88
88
|
|
|
89
89
|
## LICENSE
|
|
90
90
|
|
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
|
@@ -16,11 +16,11 @@ const combined = require("combined-stream");
|
|
|
16
16
|
const pm = require("picomatch");
|
|
17
17
|
const yaml = require("js-yaml");
|
|
18
18
|
const which = require("which");
|
|
19
|
-
const lib_v4_1 = require("
|
|
20
|
-
const types_1 = require("
|
|
21
|
-
const module_1 = require("
|
|
22
|
-
const host_1 = require("
|
|
23
|
-
const util_1 = require("
|
|
19
|
+
const lib_v4_1 = require("@e-mc/module/lib-v4");
|
|
20
|
+
const types_1 = require("@e-mc/types");
|
|
21
|
+
const module_1 = require("@e-mc/module");
|
|
22
|
+
const host_1 = require("@e-mc/request/http/host");
|
|
23
|
+
const util_1 = require("@e-mc/request/util");
|
|
24
24
|
const kSession = Symbol('session');
|
|
25
25
|
const kHttpVersion = Symbol('httpVersion');
|
|
26
26
|
const kIpVersion = Symbol('ipVersion');
|
|
@@ -181,7 +181,7 @@ function resetHttpHost(version) {
|
|
|
181
181
|
const host = HTTP.HOST[origin];
|
|
182
182
|
if (host.secure && host.version === 1) {
|
|
183
183
|
const failed = host.failed(2, true);
|
|
184
|
-
if (failed === 0 && host.failed(2, true) < 10
|
|
184
|
+
if (failed === 0 && host.failed(2, true) < 10 || failed < 3 && host.success(2, true) > 0) {
|
|
185
185
|
host.version = version;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -262,7 +262,7 @@ function validateCerts(certs) {
|
|
|
262
262
|
return [text, file];
|
|
263
263
|
}
|
|
264
264
|
function abortHeaders(href, request, options) {
|
|
265
|
-
const reason = (0, types_1.errorValue)("Aborted by client"
|
|
265
|
+
const reason = (0, types_1.errorValue)("Aborted by client", href);
|
|
266
266
|
const outAbort = options.outAbort;
|
|
267
267
|
if (outAbort) {
|
|
268
268
|
outAbort.abort(reason);
|
|
@@ -285,7 +285,7 @@ class Request extends module_1.default {
|
|
|
285
285
|
return parent ? super.purgeMemory(percent, limit) : 0;
|
|
286
286
|
}
|
|
287
287
|
static loadSettings(settings, password) {
|
|
288
|
-
if (this.enabled("process.password"
|
|
288
|
+
if (this.enabled("process.password") && !super.loadSettings({ process: settings.process }, password)) {
|
|
289
289
|
return false;
|
|
290
290
|
}
|
|
291
291
|
const { request, download } = settings;
|
|
@@ -412,9 +412,9 @@ class Request extends module_1.default {
|
|
|
412
412
|
break;
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
LOG_HTTP = this.hasLogType(1024
|
|
416
|
-
LOG_TIMEPROCESS = this.hasLogType(256
|
|
417
|
-
LOG_STDOUT = module_1.default.hasLogType(32768
|
|
415
|
+
LOG_HTTP = this.hasLogType(1024);
|
|
416
|
+
LOG_TIMEPROCESS = this.hasLogType(256);
|
|
417
|
+
LOG_STDOUT = module_1.default.hasLogType(32768);
|
|
418
418
|
return true;
|
|
419
419
|
}
|
|
420
420
|
static readCACert(value, cache) {
|
|
@@ -439,143 +439,143 @@ class Request extends module_1.default {
|
|
|
439
439
|
static fromStatusCode(value) {
|
|
440
440
|
if ((value = +value) < 200) {
|
|
441
441
|
switch (value) {
|
|
442
|
-
case 100
|
|
442
|
+
case 100:
|
|
443
443
|
return 'Continue';
|
|
444
|
-
case 101
|
|
444
|
+
case 101:
|
|
445
445
|
return 'Switching Protocol';
|
|
446
|
-
case 102
|
|
446
|
+
case 102:
|
|
447
447
|
return 'Processing';
|
|
448
|
-
case 103
|
|
448
|
+
case 103:
|
|
449
449
|
return 'Early Hints';
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
else if (value < 300) {
|
|
453
453
|
switch (value) {
|
|
454
|
-
case 200
|
|
454
|
+
case 200:
|
|
455
455
|
return 'OK';
|
|
456
|
-
case 201
|
|
456
|
+
case 201:
|
|
457
457
|
return 'Created';
|
|
458
|
-
case 202
|
|
458
|
+
case 202:
|
|
459
459
|
return 'Accepted';
|
|
460
|
-
case 203
|
|
460
|
+
case 203:
|
|
461
461
|
return 'Non-Authoritative Information';
|
|
462
|
-
case 204
|
|
462
|
+
case 204:
|
|
463
463
|
return 'No Content';
|
|
464
|
-
case 205
|
|
464
|
+
case 205:
|
|
465
465
|
return 'Reset Content';
|
|
466
|
-
case 206
|
|
466
|
+
case 206:
|
|
467
467
|
return 'Partial Content';
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
else if (value < 400) {
|
|
471
471
|
switch (value) {
|
|
472
|
-
case 300
|
|
472
|
+
case 300:
|
|
473
473
|
return 'Multiple Choice';
|
|
474
|
-
case 301
|
|
474
|
+
case 301:
|
|
475
475
|
return 'Moved Permanently';
|
|
476
|
-
case 302
|
|
476
|
+
case 302:
|
|
477
477
|
return 'Found';
|
|
478
|
-
case 303
|
|
478
|
+
case 303:
|
|
479
479
|
return 'See Other';
|
|
480
|
-
case 304
|
|
480
|
+
case 304:
|
|
481
481
|
return 'Not Modified';
|
|
482
|
-
case 305
|
|
482
|
+
case 305:
|
|
483
483
|
return 'Use Proxy';
|
|
484
|
-
case 307
|
|
484
|
+
case 307:
|
|
485
485
|
return 'Temporary Redirect';
|
|
486
|
-
case 308
|
|
486
|
+
case 308:
|
|
487
487
|
return 'Permanent Redirect';
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
else if (value < 500) {
|
|
491
491
|
switch (value) {
|
|
492
|
-
case 400
|
|
492
|
+
case 400:
|
|
493
493
|
return 'Bad Request';
|
|
494
|
-
case 401
|
|
494
|
+
case 401:
|
|
495
495
|
return 'Upgrade Required';
|
|
496
|
-
case 402
|
|
496
|
+
case 402:
|
|
497
497
|
return 'Payment Required';
|
|
498
|
-
case 403
|
|
498
|
+
case 403:
|
|
499
499
|
return 'Forbidden';
|
|
500
|
-
case 404
|
|
500
|
+
case 404:
|
|
501
501
|
return 'Not Found';
|
|
502
|
-
case 405
|
|
502
|
+
case 405:
|
|
503
503
|
return 'Method Not Allowed';
|
|
504
|
-
case 406
|
|
504
|
+
case 406:
|
|
505
505
|
return 'Not Acceptable';
|
|
506
|
-
case 407
|
|
506
|
+
case 407:
|
|
507
507
|
return 'Proxy Authentication Required';
|
|
508
|
-
case 408
|
|
508
|
+
case 408:
|
|
509
509
|
return 'Request Timeout';
|
|
510
|
-
case 409
|
|
510
|
+
case 409:
|
|
511
511
|
return 'Conflict';
|
|
512
|
-
case 410
|
|
512
|
+
case 410:
|
|
513
513
|
return 'Gone';
|
|
514
|
-
case 411
|
|
514
|
+
case 411:
|
|
515
515
|
return 'Length Required';
|
|
516
|
-
case 412
|
|
516
|
+
case 412:
|
|
517
517
|
return 'Precondition Failed';
|
|
518
|
-
case 413
|
|
518
|
+
case 413:
|
|
519
519
|
return 'Payload Too Large';
|
|
520
|
-
case 414
|
|
520
|
+
case 414:
|
|
521
521
|
return 'URI Too Long';
|
|
522
|
-
case 415
|
|
522
|
+
case 415:
|
|
523
523
|
return 'Unsupported Media Type';
|
|
524
|
-
case 416
|
|
524
|
+
case 416:
|
|
525
525
|
return 'Range Not Satisfiable';
|
|
526
|
-
case 417
|
|
526
|
+
case 417:
|
|
527
527
|
return 'Expectation Failed';
|
|
528
|
-
case 421
|
|
528
|
+
case 421:
|
|
529
529
|
return 'Misdirected Request';
|
|
530
|
-
case 422
|
|
530
|
+
case 422:
|
|
531
531
|
return 'Unprocessable Entity';
|
|
532
|
-
case 423
|
|
532
|
+
case 423:
|
|
533
533
|
return 'Locked';
|
|
534
|
-
case 424
|
|
534
|
+
case 424:
|
|
535
535
|
return 'Failed Dependency';
|
|
536
|
-
case 425
|
|
536
|
+
case 425:
|
|
537
537
|
return 'Too Early';
|
|
538
|
-
case 426
|
|
538
|
+
case 426:
|
|
539
539
|
return 'Upgrade Required';
|
|
540
|
-
case 428
|
|
540
|
+
case 428:
|
|
541
541
|
return 'Precondition Required';
|
|
542
|
-
case 429
|
|
542
|
+
case 429:
|
|
543
543
|
return 'Too Many Requests';
|
|
544
|
-
case 431
|
|
544
|
+
case 431:
|
|
545
545
|
return 'Request Header Fields Too Large';
|
|
546
|
-
case 451
|
|
546
|
+
case 451:
|
|
547
547
|
return 'Unavailable For Legal Reasons';
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
else {
|
|
551
551
|
switch (value) {
|
|
552
|
-
case 500
|
|
552
|
+
case 500:
|
|
553
553
|
return 'Internal Server Error';
|
|
554
|
-
case 501
|
|
554
|
+
case 501:
|
|
555
555
|
return 'Not Implemented';
|
|
556
|
-
case 502
|
|
556
|
+
case 502:
|
|
557
557
|
return 'Bad Gateway';
|
|
558
|
-
case 503
|
|
558
|
+
case 503:
|
|
559
559
|
return 'Service Unavailable';
|
|
560
|
-
case 504
|
|
560
|
+
case 504:
|
|
561
561
|
return 'Gateway Timeout';
|
|
562
|
-
case 505
|
|
562
|
+
case 505:
|
|
563
563
|
return 'HTTP Version Not Supported';
|
|
564
|
-
case 506
|
|
564
|
+
case 506:
|
|
565
565
|
return 'Variant Also Negotiates';
|
|
566
|
-
case 507
|
|
566
|
+
case 507:
|
|
567
567
|
return 'Insufficient Storage';
|
|
568
|
-
case 508
|
|
568
|
+
case 508:
|
|
569
569
|
return 'Loop Detected';
|
|
570
|
-
case 509
|
|
570
|
+
case 509:
|
|
571
571
|
return 'Bandwidth Limit Exceeded';
|
|
572
|
-
case 510
|
|
572
|
+
case 510:
|
|
573
573
|
return 'Not Extended';
|
|
574
|
-
case 511
|
|
574
|
+
case 511:
|
|
575
575
|
return 'Network Authentication Required';
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
|
-
return "Unknown"
|
|
578
|
+
return "Unknown";
|
|
579
579
|
}
|
|
580
580
|
static defineHttpAgent(options) {
|
|
581
581
|
const { keepAlive, timeout = 0 } = options;
|
|
@@ -632,14 +632,14 @@ class Request extends module_1.default {
|
|
|
632
632
|
this.startTime = Date.now();
|
|
633
633
|
this.readExpect = 'none';
|
|
634
634
|
this.proxy = null;
|
|
635
|
-
this._moduleName = "request"
|
|
635
|
+
this._moduleName = "request";
|
|
636
636
|
this._threadable = true;
|
|
637
637
|
this._config = {
|
|
638
|
-
timeout: 60000
|
|
639
|
-
connectTimeout: 20 * 1000
|
|
638
|
+
timeout: 60000,
|
|
639
|
+
connectTimeout: 20 * 1000,
|
|
640
640
|
redirectLimit: 10,
|
|
641
|
-
retryWait: 1000
|
|
642
|
-
retryAfter: 30 * 1000
|
|
641
|
+
retryWait: 1000,
|
|
642
|
+
retryAfter: 30 * 1000,
|
|
643
643
|
retryLimit: 5
|
|
644
644
|
};
|
|
645
645
|
this[_a] = false;
|
|
@@ -754,7 +754,7 @@ class Request extends module_1.default {
|
|
|
754
754
|
module_1.default.formatMessage(...message);
|
|
755
755
|
}
|
|
756
756
|
else {
|
|
757
|
-
this.formatMessage(1024
|
|
757
|
+
this.formatMessage(1024, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
|
|
758
758
|
messages.forEach(args => {
|
|
759
759
|
args[4].titleIndent = true;
|
|
760
760
|
module_1.default.formatMessage(...args);
|
|
@@ -784,7 +784,7 @@ class Request extends module_1.default {
|
|
|
784
784
|
}
|
|
785
785
|
init(config) {
|
|
786
786
|
if (config) {
|
|
787
|
-
const { headers, httpVersion, ipVersion, requestTimeout } = config;
|
|
787
|
+
const { headers, httpVersion, ipVersion, requestTimeout, readTimeout = requestTimeout } = config;
|
|
788
788
|
if ((0, types_1.isObject)(headers)) {
|
|
789
789
|
setOutgoingHeaders(this[kHeaders] || (this[kHeaders] = {}), headers);
|
|
790
790
|
}
|
|
@@ -794,8 +794,8 @@ class Request extends module_1.default {
|
|
|
794
794
|
if (ipVersion !== undefined) {
|
|
795
795
|
this.ipVersion = ipVersion;
|
|
796
796
|
}
|
|
797
|
-
if (
|
|
798
|
-
this.readTimeout = (0, util_1.fromSeconds)(
|
|
797
|
+
if (readTimeout !== undefined) {
|
|
798
|
+
this.readTimeout = (0, util_1.fromSeconds)(readTimeout);
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
return this;
|
|
@@ -816,7 +816,7 @@ class Request extends module_1.default {
|
|
|
816
816
|
this._config.redirectLimit = redirectLimit;
|
|
817
817
|
}
|
|
818
818
|
if (retryWait >= 0) {
|
|
819
|
-
this._config.retryWait = Math.min(retryWait, 600 * 1000
|
|
819
|
+
this._config.retryWait = Math.min(retryWait, 600 * 1000);
|
|
820
820
|
}
|
|
821
821
|
if (retryAfter >= 0) {
|
|
822
822
|
this._config.retryAfter = Math.min(retryAfter, module_1.default.MAX_TIMEOUT);
|
|
@@ -955,35 +955,35 @@ class Request extends module_1.default {
|
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
|
-
statusOn(code,
|
|
959
|
-
if (typeof
|
|
960
|
-
callback =
|
|
961
|
-
|
|
958
|
+
statusOn(code, globUrl = '*', callback) {
|
|
959
|
+
if (typeof globUrl === 'function') {
|
|
960
|
+
callback = globUrl;
|
|
961
|
+
globUrl = '*';
|
|
962
962
|
}
|
|
963
|
-
if ((0, types_1.isString)(
|
|
963
|
+
if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
|
|
964
964
|
const on = this[kStatusOn] || (this[kStatusOn] = new Map());
|
|
965
965
|
for (const item of !Array.isArray(code) ? [code] : code) {
|
|
966
966
|
let status = on.get(item);
|
|
967
967
|
if (!status) {
|
|
968
968
|
on.set(item, status = []);
|
|
969
969
|
}
|
|
970
|
-
status.push([
|
|
970
|
+
status.push([globUrl, callback]);
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
973
|
}
|
|
974
|
-
headersOn(name,
|
|
975
|
-
if (typeof
|
|
976
|
-
callback =
|
|
977
|
-
|
|
974
|
+
headersOn(name, globUrl = '*', callback) {
|
|
975
|
+
if (typeof globUrl === 'function') {
|
|
976
|
+
callback = globUrl;
|
|
977
|
+
globUrl = '*';
|
|
978
978
|
}
|
|
979
|
-
if ((0, types_1.isString)(
|
|
979
|
+
if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
|
|
980
980
|
const on = this[kHeadersOn] || (this[kHeadersOn] = new Map());
|
|
981
981
|
for (const item of !Array.isArray(name) ? [name] : name) {
|
|
982
982
|
let headers = on.get(item);
|
|
983
983
|
if (!headers) {
|
|
984
984
|
on.set(item, headers = []);
|
|
985
985
|
}
|
|
986
|
-
headers.push([
|
|
986
|
+
headers.push([globUrl, callback]);
|
|
987
987
|
}
|
|
988
988
|
}
|
|
989
989
|
}
|
|
@@ -993,7 +993,7 @@ class Request extends module_1.default {
|
|
|
993
993
|
}
|
|
994
994
|
async aria2c(uri, options) {
|
|
995
995
|
if (!ARIA2.BIN) {
|
|
996
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
996
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Binary not found"));
|
|
997
997
|
}
|
|
998
998
|
if (typeof uri === 'string' && module_1.default.isURL(uri)) {
|
|
999
999
|
try {
|
|
@@ -1061,15 +1061,15 @@ class Request extends module_1.default {
|
|
|
1061
1061
|
}
|
|
1062
1062
|
if (!(0, types_1.isString)(pathname)) {
|
|
1063
1063
|
if (this.host) {
|
|
1064
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1064
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Invalid parameters", 'pathname'));
|
|
1065
1065
|
}
|
|
1066
1066
|
pathname = process.cwd();
|
|
1067
1067
|
}
|
|
1068
1068
|
if ((this.host || this.hasOwnPermission()) && !this.canWrite(pathname = path.resolve(pathname.trim()))) {
|
|
1069
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1069
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Unsupported access", pathname));
|
|
1070
1070
|
}
|
|
1071
1071
|
if (!module_1.default.createDir(pathname)) {
|
|
1072
|
-
return Promise.reject((0, types_1.errorMessage)("aria2"
|
|
1072
|
+
return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
|
|
1073
1073
|
}
|
|
1074
1074
|
silent ?? (silent = this[kSingleton]);
|
|
1075
1075
|
return new Promise((resolve, reject) => {
|
|
@@ -1234,11 +1234,11 @@ class Request extends module_1.default {
|
|
|
1234
1234
|
args = binOpts.concat(args);
|
|
1235
1235
|
}
|
|
1236
1236
|
if (args.length) {
|
|
1237
|
-
if (module_1.default.hasLogType(32768
|
|
1238
|
-
this.formatMessage(32768
|
|
1237
|
+
if (module_1.default.hasLogType(32768)) {
|
|
1238
|
+
this.formatMessage(32768, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
|
|
1239
1239
|
}
|
|
1240
1240
|
else {
|
|
1241
|
-
this.addLog(types_1.STATUS_TYPE.INFO, path.basename(ARIA2.BIN) + ' ' + args.join(' '), "aria2"
|
|
1241
|
+
this.addLog(types_1.STATUS_TYPE.INFO, path.basename(ARIA2.BIN) + ' ' + args.join(' '), "aria2");
|
|
1242
1242
|
}
|
|
1243
1243
|
}
|
|
1244
1244
|
opts.push(`"${escapeQuote(uri)}"`);
|
|
@@ -1282,18 +1282,18 @@ class Request extends module_1.default {
|
|
|
1282
1282
|
break;
|
|
1283
1283
|
}
|
|
1284
1284
|
case 'ERR':
|
|
1285
|
-
fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file"
|
|
1285
|
+
fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file", path.basename(file)], err, { type: 32, fatal: false }));
|
|
1286
1286
|
break;
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
1289
1289
|
if (result.length && !silent && LOG_HTTP && LOG_TIMEPROCESS) {
|
|
1290
|
-
this.writeTimeProcess("aria2"
|
|
1290
|
+
this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
|
|
1291
1291
|
}
|
|
1292
|
-
this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2"
|
|
1292
|
+
this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2", uri);
|
|
1293
1293
|
resolve(result);
|
|
1294
1294
|
}
|
|
1295
1295
|
else {
|
|
1296
|
-
reject((0, types_1.errorValue)(message || "Unknown"
|
|
1296
|
+
reject((0, types_1.errorValue)(message || "Unknown", 'Exit status: ' + code));
|
|
1297
1297
|
}
|
|
1298
1298
|
})
|
|
1299
1299
|
.on('error', err => errorResponse(pid, err));
|
|
@@ -1329,9 +1329,9 @@ class Request extends module_1.default {
|
|
|
1329
1329
|
}
|
|
1330
1330
|
else {
|
|
1331
1331
|
const current = (0, types_1.getLogCurrent)();
|
|
1332
|
-
progressBar = current?.type === 128
|
|
1332
|
+
progressBar = current?.type === 128 && current.title === "aria2";
|
|
1333
1333
|
}
|
|
1334
|
-
this.formatMessage(128
|
|
1334
|
+
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 });
|
|
1335
1335
|
}
|
|
1336
1336
|
ARIA2.PID_QUEUE.push(item);
|
|
1337
1337
|
}
|
|
@@ -1339,7 +1339,7 @@ class Request extends module_1.default {
|
|
|
1339
1339
|
clearTimer();
|
|
1340
1340
|
}
|
|
1341
1341
|
}
|
|
1342
|
-
}, (ARIA2.UPDATE_STATUS || 30) * 1000
|
|
1342
|
+
}, (ARIA2.UPDATE_STATUS || 30) * 1000);
|
|
1343
1343
|
}
|
|
1344
1344
|
ARIA2.PID_QUEUE.push([pid, uri, this.broadcastId || undefined]);
|
|
1345
1345
|
}
|
|
@@ -1418,9 +1418,9 @@ class Request extends module_1.default {
|
|
|
1418
1418
|
}
|
|
1419
1419
|
const checkEncoding = (response, statusCode, contentEncoding = '') => {
|
|
1420
1420
|
switch (statusCode) {
|
|
1421
|
-
case 206
|
|
1422
|
-
request.emit('error', (0, types_1.errorValue)("Aborted"
|
|
1423
|
-
case 204
|
|
1421
|
+
case 206:
|
|
1422
|
+
request.emit('error', (0, types_1.errorValue)("Aborted", 'Partial content'));
|
|
1423
|
+
case 204:
|
|
1424
1424
|
return;
|
|
1425
1425
|
}
|
|
1426
1426
|
const chunkSize = outStream?.writableHighWaterMark;
|
|
@@ -1469,7 +1469,7 @@ class Request extends module_1.default {
|
|
|
1469
1469
|
}
|
|
1470
1470
|
}
|
|
1471
1471
|
if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
|
|
1472
|
-
request = ((_p = this[kSession][0])[origin] || (_p[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215
|
|
1472
|
+
request = ((_p = this[kSession][0])[origin] || (_p[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 });
|
|
1473
1473
|
if (getting) {
|
|
1474
1474
|
const listenerMap = {};
|
|
1475
1475
|
const onEvent = request.on.bind(request);
|
|
@@ -1478,7 +1478,7 @@ class Request extends module_1.default {
|
|
|
1478
1478
|
request.on('response', response => {
|
|
1479
1479
|
connected = true;
|
|
1480
1480
|
const statusCode = response[':status'];
|
|
1481
|
-
if (this.matchStatus(statusCode, url, response, request, options) && statusCode >= 200
|
|
1481
|
+
if (this.matchStatus(statusCode, url, response, request, options) && statusCode >= 200 && statusCode < 300) {
|
|
1482
1482
|
if (emitter = checkEncoding(request, statusCode, response['content-encoding'])) {
|
|
1483
1483
|
for (const event in listenerMap) {
|
|
1484
1484
|
listenerMap[event].forEach(listener => {
|
|
@@ -1562,7 +1562,7 @@ class Request extends module_1.default {
|
|
|
1562
1562
|
}
|
|
1563
1563
|
}
|
|
1564
1564
|
catch (err) {
|
|
1565
|
-
this.checkPackage(err, pkg, "Unknown"
|
|
1565
|
+
this.checkPackage(err, pkg, "Unknown");
|
|
1566
1566
|
}
|
|
1567
1567
|
}
|
|
1568
1568
|
else if (keepAlive === false) {
|
|
@@ -1599,7 +1599,7 @@ class Request extends module_1.default {
|
|
|
1599
1599
|
}, response => {
|
|
1600
1600
|
const statusCode = response.statusCode;
|
|
1601
1601
|
const incoming = response.headers;
|
|
1602
|
-
if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200
|
|
1602
|
+
if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200 && statusCode < 300) {
|
|
1603
1603
|
let source = checkEncoding(response, statusCode, incoming['content-encoding']);
|
|
1604
1604
|
if (source) {
|
|
1605
1605
|
source.once('finish', () => request.emit('end'));
|
|
@@ -1663,7 +1663,7 @@ class Request extends module_1.default {
|
|
|
1663
1663
|
const ac = new AbortController();
|
|
1664
1664
|
this[kDownloading].add(options.outAbort = ac);
|
|
1665
1665
|
stream.addAbortSignal(ac.signal, request);
|
|
1666
|
-
this.signal.addEventListener('abort', () => ac.abort(new Error("Aborted by process"
|
|
1666
|
+
this.signal.addEventListener('abort', () => ac.abort(new Error("Aborted by process")), { once: true });
|
|
1667
1667
|
}
|
|
1668
1668
|
if (posting) {
|
|
1669
1669
|
if ((0, types_1.isString)(postData) || Buffer.isBuffer(postData)) {
|
|
@@ -1693,7 +1693,7 @@ class Request extends module_1.default {
|
|
|
1693
1693
|
options = contentType;
|
|
1694
1694
|
contentType = undefined;
|
|
1695
1695
|
}
|
|
1696
|
-
if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data"
|
|
1696
|
+
if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data")) {
|
|
1697
1697
|
parts = data;
|
|
1698
1698
|
data = undefined;
|
|
1699
1699
|
}
|
|
@@ -1719,23 +1719,23 @@ class Request extends module_1.default {
|
|
|
1719
1719
|
delete headers[attr];
|
|
1720
1720
|
}
|
|
1721
1721
|
}
|
|
1722
|
-
if (parts || contentType === "multipart/form-data"
|
|
1722
|
+
if (parts || contentType === "multipart/form-data" || contentType === 'form-data') {
|
|
1723
1723
|
let valid;
|
|
1724
1724
|
if ((0, types_1.isArray)(parts)) {
|
|
1725
1725
|
const write = combined.create();
|
|
1726
1726
|
const boundary = (0, types_1.generateUUID)().replace(/-/g, '');
|
|
1727
|
-
contentType = "multipart/form-data"
|
|
1727
|
+
contentType = "multipart/form-data" + `; boundary="${boundary}"`;
|
|
1728
1728
|
let contentLength = 0;
|
|
1729
1729
|
const createPart = (name, filename, type) => {
|
|
1730
|
-
const form = ["--"
|
|
1730
|
+
const form = ["--" + boundary, `Content-Disposition: form-data; name="${escapeQuote(name)}"` + (filename ? `; filename="${escapeQuote(filename)}"` : ''), "\r\n"];
|
|
1731
1731
|
if (type) {
|
|
1732
1732
|
form.splice(2, 0, 'Content-Type: ' + type);
|
|
1733
1733
|
}
|
|
1734
|
-
return form.join("\r\n"
|
|
1734
|
+
return form.join("\r\n");
|
|
1735
1735
|
};
|
|
1736
1736
|
const addValue = (name, value) => {
|
|
1737
1737
|
if (value !== undefined) {
|
|
1738
|
-
const disposition = createPart(name) + module_1.default.asString(value) + "\r\n"
|
|
1738
|
+
const disposition = createPart(name) + module_1.default.asString(value) + "\r\n";
|
|
1739
1739
|
write.append(disposition);
|
|
1740
1740
|
contentLength += Buffer.byteLength(disposition);
|
|
1741
1741
|
}
|
|
@@ -1765,7 +1765,7 @@ class Request extends module_1.default {
|
|
|
1765
1765
|
target = Buffer.concat(chunks);
|
|
1766
1766
|
}
|
|
1767
1767
|
if (!Buffer.isBuffer(target)) {
|
|
1768
|
-
throw (0, types_1.errorMessage)('File', "Unknown"
|
|
1768
|
+
throw (0, types_1.errorMessage)('File', "Unknown", "multipart/form-data");
|
|
1769
1769
|
}
|
|
1770
1770
|
if (!type || !filename) {
|
|
1771
1771
|
const result = await module_1.default.resolveMime(target);
|
|
@@ -1781,11 +1781,11 @@ class Request extends module_1.default {
|
|
|
1781
1781
|
filename = (0, types_1.generateUUID)() + '.' + ext;
|
|
1782
1782
|
}
|
|
1783
1783
|
}
|
|
1784
|
-
const disposition = createPart(name, filename, type || "application/octet-stream"
|
|
1784
|
+
const disposition = createPart(name, filename, type || "application/octet-stream");
|
|
1785
1785
|
write.append(disposition);
|
|
1786
1786
|
write.append(target);
|
|
1787
|
-
write.append("\r\n"
|
|
1788
|
-
contentLength += Buffer.byteLength(disposition) + target.length + 2
|
|
1787
|
+
write.append("\r\n");
|
|
1788
|
+
contentLength += Buffer.byteLength(disposition) + target.length + 2;
|
|
1789
1789
|
valid = true;
|
|
1790
1790
|
}
|
|
1791
1791
|
catch (err) {
|
|
@@ -1797,13 +1797,13 @@ class Request extends module_1.default {
|
|
|
1797
1797
|
}
|
|
1798
1798
|
}
|
|
1799
1799
|
if (valid) {
|
|
1800
|
-
write.append("--"
|
|
1801
|
-
headers['content-length'] = (contentLength + 38
|
|
1800
|
+
write.append("--" + boundary + "--" + "\r\n");
|
|
1801
|
+
headers['content-length'] = (contentLength + 38).toString();
|
|
1802
1802
|
data = write;
|
|
1803
1803
|
}
|
|
1804
1804
|
}
|
|
1805
1805
|
if (!valid) {
|
|
1806
|
-
return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data"
|
|
1806
|
+
return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data"));
|
|
1807
1807
|
}
|
|
1808
1808
|
}
|
|
1809
1809
|
else {
|
|
@@ -1813,19 +1813,19 @@ class Request extends module_1.default {
|
|
|
1813
1813
|
if (!(0, types_1.isPlainObject)(data)) {
|
|
1814
1814
|
data = module_1.default.asString(data);
|
|
1815
1815
|
}
|
|
1816
|
-
else if (contentType === "application/x-www-form-urlencoded"
|
|
1816
|
+
else if (contentType === "application/x-www-form-urlencoded") {
|
|
1817
1817
|
data = qs.stringify(data);
|
|
1818
1818
|
}
|
|
1819
1819
|
else {
|
|
1820
1820
|
data = JSON.stringify(data);
|
|
1821
|
-
contentType || (contentType = "application/json"
|
|
1821
|
+
contentType || (contentType = "application/json");
|
|
1822
1822
|
}
|
|
1823
1823
|
headers['content-length'] = Buffer.byteLength(data, (0, types_1.getEncoding)(dataEncoding)).toString();
|
|
1824
1824
|
}
|
|
1825
1825
|
options.method = 'POST';
|
|
1826
1826
|
options.httpVersion = 1;
|
|
1827
1827
|
options.postData = data;
|
|
1828
|
-
headers['content-type'] = contentType || "text/plain"
|
|
1828
|
+
headers['content-type'] = contentType || "text/plain";
|
|
1829
1829
|
return this.get(uri, options);
|
|
1830
1830
|
}
|
|
1831
1831
|
async get(uri, options = {}) {
|
|
@@ -1863,7 +1863,7 @@ class Request extends module_1.default {
|
|
|
1863
1863
|
}
|
|
1864
1864
|
if (pipeTo) {
|
|
1865
1865
|
if ((0, types_1.isString)(pipeTo)) {
|
|
1866
|
-
outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536
|
|
1866
|
+
outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536 : 4096 });
|
|
1867
1867
|
request.outStream = outStream;
|
|
1868
1868
|
}
|
|
1869
1869
|
else {
|
|
@@ -1879,10 +1879,10 @@ class Request extends module_1.default {
|
|
|
1879
1879
|
({ httpVersion, outAbort } = request);
|
|
1880
1880
|
const isAborted = () => client.destroyed || httpVersion === 2 && client.aborted;
|
|
1881
1881
|
const isRetry = (value) => (0, util_1.isRetryable)(value) && ++retries <= this._config.retryLimit;
|
|
1882
|
-
const isUnsupported = (value) => value === 421
|
|
1882
|
+
const isUnsupported = (value) => value === 421 || value === 505;
|
|
1883
1883
|
const isDowngrade = (err) => err instanceof Error && (err.code === 'ERR_HTTP2_ERROR' || isUnsupported(Math.abs(err.errno)));
|
|
1884
|
-
const wasAborted = (err) => err instanceof Error && err.message.startsWith("Aborted"
|
|
1885
|
-
const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024
|
|
1884
|
+
const wasAborted = (err) => err instanceof Error && err.message.startsWith("Aborted");
|
|
1885
|
+
const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { titleBgColor: 'bgGrey', titleColor: 'yellow' });
|
|
1886
1886
|
const formatNgFlags = (value, statusCode, location) => location ? `Using HTTP 1.1 for URL redirect (${location})` : formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
|
|
1887
1887
|
const abortResponse = () => {
|
|
1888
1888
|
if (closed) {
|
|
@@ -1922,7 +1922,7 @@ class Request extends module_1.default {
|
|
|
1922
1922
|
if (readTimeout > 0) {
|
|
1923
1923
|
timeout = setTimeout(() => {
|
|
1924
1924
|
abortResponse();
|
|
1925
|
-
throwError((0, types_1.errorValue)("Timeout was exceeded"
|
|
1925
|
+
throwError((0, types_1.errorValue)("Timeout was exceeded", href.toString()));
|
|
1926
1926
|
}, readTimeout);
|
|
1927
1927
|
}
|
|
1928
1928
|
if (log) {
|
|
@@ -1977,15 +1977,15 @@ class Request extends module_1.default {
|
|
|
1977
1977
|
}
|
|
1978
1978
|
}
|
|
1979
1979
|
if (mibsTime) {
|
|
1980
|
-
const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000
|
|
1980
|
+
const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000);
|
|
1981
1981
|
if (unit < 1) {
|
|
1982
|
-
messageUnit = Math.ceil(unit * 1000
|
|
1982
|
+
messageUnit = Math.ceil(unit * 1000) + 'KiB/s';
|
|
1983
1983
|
}
|
|
1984
|
-
else if (unit < 1000
|
|
1984
|
+
else if (unit < 1000) {
|
|
1985
1985
|
messageUnit = unit.toPrecision(3) + 'MiB/s';
|
|
1986
1986
|
}
|
|
1987
1987
|
else {
|
|
1988
|
-
messageUnit = (unit / 1000
|
|
1988
|
+
messageUnit = (unit / 1000).toPrecision(3) + 'GiB/s';
|
|
1989
1989
|
}
|
|
1990
1990
|
}
|
|
1991
1991
|
if (typeof buffer === 'string') {
|
|
@@ -2019,7 +2019,7 @@ class Request extends module_1.default {
|
|
|
2019
2019
|
}
|
|
2020
2020
|
catch (err) {
|
|
2021
2021
|
if (!silent && !this[kSingleton] && !(packageName && this.checkPackage(err, packageName))) {
|
|
2022
|
-
this.writeFail(['Unable to parse URI response', format], err, 1024
|
|
2022
|
+
this.writeFail(['Unable to parse URI response', format], err, 1024);
|
|
2023
2023
|
}
|
|
2024
2024
|
result = null;
|
|
2025
2025
|
}
|
|
@@ -2039,7 +2039,7 @@ class Request extends module_1.default {
|
|
|
2039
2039
|
}
|
|
2040
2040
|
resolve(result);
|
|
2041
2041
|
if (log) {
|
|
2042
|
-
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024
|
|
2042
|
+
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: LOG_STDOUT });
|
|
2043
2043
|
}
|
|
2044
2044
|
});
|
|
2045
2045
|
host.success(httpVersion);
|
|
@@ -2115,7 +2115,7 @@ class Request extends module_1.default {
|
|
|
2115
2115
|
host.failed(2);
|
|
2116
2116
|
if (host.version > 1) {
|
|
2117
2117
|
if (!silent) {
|
|
2118
|
-
this.formatMessage(1024
|
|
2118
|
+
this.formatMessage(1024, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
|
|
2119
2119
|
}
|
|
2120
2120
|
host.version = 1;
|
|
2121
2121
|
}
|
|
@@ -2128,18 +2128,18 @@ class Request extends module_1.default {
|
|
|
2128
2128
|
return;
|
|
2129
2129
|
}
|
|
2130
2130
|
const statusCode = headers[':status'];
|
|
2131
|
-
if (statusCode < 300
|
|
2131
|
+
if (statusCode < 300) {
|
|
2132
2132
|
acceptResponse(headers);
|
|
2133
2133
|
}
|
|
2134
|
-
else if (statusCode < 400
|
|
2134
|
+
else if (statusCode < 400) {
|
|
2135
2135
|
redirectResponse(statusCode, headers.location);
|
|
2136
2136
|
}
|
|
2137
|
-
else if (statusCode === 401
|
|
2138
|
-
statusCode === 402
|
|
2139
|
-
statusCode === 403
|
|
2140
|
-
statusCode === 404
|
|
2141
|
-
statusCode === 407
|
|
2142
|
-
statusCode === 410
|
|
2137
|
+
else if (statusCode === 401 ||
|
|
2138
|
+
statusCode === 402 ||
|
|
2139
|
+
statusCode === 403 ||
|
|
2140
|
+
statusCode === 404 ||
|
|
2141
|
+
statusCode === 407 ||
|
|
2142
|
+
statusCode === 410) {
|
|
2143
2143
|
throwError(formatStatus(statusCode), outAbort);
|
|
2144
2144
|
}
|
|
2145
2145
|
else if (isRetry(statusCode)) {
|
|
@@ -2179,10 +2179,10 @@ class Request extends module_1.default {
|
|
|
2179
2179
|
return;
|
|
2180
2180
|
}
|
|
2181
2181
|
switch (!isDowngrade(err) && await host.hasProtocol(2)) {
|
|
2182
|
-
case 1
|
|
2182
|
+
case 1:
|
|
2183
2183
|
errorResponse(err);
|
|
2184
2184
|
break;
|
|
2185
|
-
case 2
|
|
2185
|
+
case 2:
|
|
2186
2186
|
retryDownload(false, err);
|
|
2187
2187
|
break;
|
|
2188
2188
|
default:
|
|
@@ -2198,10 +2198,10 @@ class Request extends module_1.default {
|
|
|
2198
2198
|
return;
|
|
2199
2199
|
}
|
|
2200
2200
|
const statusCode = res.statusCode;
|
|
2201
|
-
if (statusCode < 300
|
|
2201
|
+
if (statusCode < 300) {
|
|
2202
2202
|
acceptResponse(res.headers);
|
|
2203
2203
|
}
|
|
2204
|
-
else if (statusCode < 400
|
|
2204
|
+
else if (statusCode < 400) {
|
|
2205
2205
|
redirectResponse(statusCode, res.headers.location);
|
|
2206
2206
|
}
|
|
2207
2207
|
else if (isRetry(statusCode)) {
|
|
@@ -2231,7 +2231,7 @@ class Request extends module_1.default {
|
|
|
2231
2231
|
retryTimeout();
|
|
2232
2232
|
}
|
|
2233
2233
|
else {
|
|
2234
|
-
throwError(formatStatus(408
|
|
2234
|
+
throwError(formatStatus(408));
|
|
2235
2235
|
}
|
|
2236
2236
|
});
|
|
2237
2237
|
}
|
|
@@ -2273,7 +2273,7 @@ class Request extends module_1.default {
|
|
|
2273
2273
|
}
|
|
2274
2274
|
}
|
|
2275
2275
|
catch (err) {
|
|
2276
|
-
this.writeFail(["Unable to process headers"
|
|
2276
|
+
this.writeFail(["Unable to process headers", url.origin], err, { type: 1024, abortable: this.abortable, fatal: false });
|
|
2277
2277
|
}
|
|
2278
2278
|
}
|
|
2279
2279
|
}
|
|
@@ -2305,7 +2305,7 @@ class Request extends module_1.default {
|
|
|
2305
2305
|
}
|
|
2306
2306
|
}
|
|
2307
2307
|
catch (err) {
|
|
2308
|
-
this.writeFail(["Unable to process headers"
|
|
2308
|
+
this.writeFail(["Unable to process headers", url.origin], err, { type: 1024, abortable: this.abortable, fatal: false });
|
|
2309
2309
|
}
|
|
2310
2310
|
}
|
|
2311
2311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.8.
|
|
24
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/module": "0.8.6",
|
|
24
|
+
"@e-mc/types": "0.8.6",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^3.0.1",
|
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
|
}
|