@e-mc/request 0.8.5 → 0.8.7

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 CHANGED
@@ -1,7 +1,11 @@
1
- Copyright 2024 Mile Square Park
1
+ Copyright 2024 An Pham
2
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:
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
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.
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
@@ -1,7 +1,91 @@
1
1
  # @e-mc/request
2
2
 
3
- PEP 402
3
+ * NodeJS 14
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { IModule, ModuleConstructor } from "./index";
16
+ import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
17
+ import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
18
+ import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
19
+
20
+ import type { ClientRequest, OutgoingHttpHeaders } from "http";
21
+ import type { LookupFunction } from "net";
22
+ import type { Writable } from "stream";
23
+
24
+ interface IRequest extends IModule {
25
+ module: RequestModule;
26
+ startTime: number;
27
+ acceptEncoding: boolean;
28
+ keepAlive: boolean | null;
29
+ readTimeout: number;
30
+ readExpect: ReadExpectType;
31
+ proxy: ProxySettings | null;
32
+ init(config?: RequestInit): this;
33
+ apply(options: ApplyOptions): this;
34
+ addDns(hostname: string, address: string, timeout: number): void;
35
+ addDns(hostname: string, address: string, family?: number | string, timeout?: number): void;
36
+ lookupDns(hostname: string): LookupFunction;
37
+ proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
38
+ statusOn(name: number | number[], callback: StatusOnCallback): void;
39
+ statusOn(name: number | number[], patternUrl: string, callback: StatusOnCallback): void;
40
+ headersOn(name: string | string[], callback: HeadersOnCallback): void;
41
+ headersOn(name: string | string[], patternUrl: string, callback: HeadersOnCallback): void;
42
+ headersOf(uri: string): OutgoingHttpHeaders | undefined;
43
+ aria2c(uri: string | URL, pathname: string): Promise<string[]>;
44
+ aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
45
+ json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
46
+ pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
47
+ opts(url: string | URL, options?: OpenOptions): HostConfig;
48
+ open(uri: string | URL, options: OpenOptions): HttpRequestClient;
49
+ head(uri: string | URL, options?: OpenOptions): ClientRequest;
50
+ post(uri: string | URL, data: unknown, contentType: string): Promise<Buffer | string | null>;
51
+ post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
52
+ post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
53
+ post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
54
+ post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
55
+ get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
56
+ detach(singleton?: boolean): void;
57
+ reset(): void;
58
+ close(): void;
59
+ set agentTimeout(value);
60
+ get agentTimeout(): number;
61
+ set httpVersion(value);
62
+ get httpVersion(): HttpProtocolVersion | null;
63
+ set ipVersion(value);
64
+ get ipVersion(): InternetProtocolVersion;
65
+ get settings(): RequestSettings;
66
+ }
67
+
68
+ interface RequestConstructor extends ModuleConstructor {
69
+ readCACert(value: string, cache?: boolean): string;
70
+ readTLSKey(value: string, cache?: boolean): string;
71
+ readTLSCert(value: string, cache?: boolean): string;
72
+ isCert(value: string): boolean;
73
+ fromURL(url: URL, value: string): string;
74
+ fromStatusCode(value: number | string): string;
75
+ defineHttpAgent(options: HttpAgentSettings): void;
76
+ defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
77
+ getAria2Path(): string;
78
+ readonly prototype: IRequest;
79
+ new(module?: RequestModule): IRequest;
80
+ }
81
+ ```
82
+
83
+ ## References
84
+
85
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/http.d.ts
86
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/request.d.ts
87
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/settings.d.ts
4
88
 
5
89
  ## LICENSE
6
90
 
7
- MIT
91
+ BSD 3-Clause
@@ -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("../../../types");
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 /* HOST_VERSION.ALT_SVC */] = 0);
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 /* QUERY_RESULT.FAIL */;
94
+ return 0;
95
95
  }
96
- const status = data[3 /* HOST_VERSION.ALPN */];
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 /* HOST_VERSION.ALPN */] = alpn === socket.alpnProtocol ? 1 /* QUERY_RESULT.OK */ : 0 /* QUERY_RESULT.FAIL */);
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 /* HOST.TIMEOUT */)
110
+ .setTimeout(10000)
111
111
  .on('timeout', () => {
112
112
  if (this._tlsConnect) {
113
- if (this.error(version) >= 10 /* HOST.MAX_ERROR */) {
114
- resolve(data[3 /* HOST_VERSION.ALPN */] = 0 /* QUERY_RESULT.FAIL */);
113
+ if (this.error(version) >= 10) {
114
+ resolve(data[3] = 0);
115
115
  }
116
116
  else {
117
- resolve(2 /* QUERY_RESULT.TIMEOUT */);
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 /* HOST_VERSION.ALPN */] = 0 /* QUERY_RESULT.FAIL */);
125
+ resolve(data[3] = 0);
126
126
  this._tlsConnect = null;
127
127
  })
128
128
  .end();
129
129
  }));
130
130
  }
131
131
  }
132
- return 1 /* QUERY_RESULT.OK */;
132
+ return 1;
133
133
  }
134
134
  success(version, status) {
135
135
  const data = this[kVersionData][version - 1];
136
- return status ? data[0 /* HOST_VERSION.SUCCESS */] : ++data[0 /* HOST_VERSION.SUCCESS */];
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 /* HOST_VERSION.FAILED */];
141
+ return data[1];
142
142
  }
143
143
  this.clearAltSvc(version);
144
- return ++data[1 /* HOST_VERSION.FAILED */];
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 /* HOST_VERSION.ERROR */];
149
+ return data[2];
150
150
  }
151
- if (data[4 /* HOST_VERSION.ALT_SVC */] !== 2) {
151
+ if (data[4] !== 2) {
152
152
  this.closeAltSvc(true);
153
153
  }
154
- return ++data[2 /* HOST_VERSION.ERROR */];
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 /* HOST_VERSION.ALT_SVC */] === 0) {
165
+ if (host[4] === 0) {
166
166
  continue;
167
167
  }
168
168
  const increment = (flag) => {
169
- host[4 /* HOST_VERSION.ALT_SVC */] = flag;
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 /* TIMEOUT.MA */ ? NaN : time + Math.min(ma * 1000 /* TIME.S */, 2147483647 /* TIMEOUT.LIMIT */),
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 /* HOST_VERSION.ALT_SVC */] !== -1;
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 /* HOST_VERSION.ALPN */] && (item[4 /* HOST_VERSION.ALT_SVC */] = -1));
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 /* HOST_VERSION.ALT_SVC */] = value;
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 /* HOST_VERSION.SUCCESS */] = 0;
292
- item[1 /* HOST_VERSION.FAILED */] = 0;
293
- item[2 /* HOST_VERSION.ERROR */] = 0;
291
+ item[0] = 0;
292
+ item[1] = 0;
293
+ item[2] = 0;
294
294
  if (index > 0) {
295
- item[3 /* HOST_VERSION.ALPN */] = -1;
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("../module/lib-v4");
20
- const types_1 = require("../types");
21
- const module_1 = require("../module");
22
- const host_1 = require("./http/host");
23
- const util_1 = require("./util");
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 /* HOST.MAX_ERROR */ || failed < 3 /* HOST.MAX_FAILED */ && host.success(2, true) > 0) {
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" /* ERR_MESSAGE.ABORTED_CLIENT */, href);
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" /* KEY_NAME.PROCESS_PASSWORD */) && !super.loadSettings({ process: settings.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 /* LOG_TYPE.HTTP */);
416
- LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
417
- LOG_STDOUT = module_1.default.hasLogType(32768 /* LOG_TYPE.STDOUT */);
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 /* HTTP_STATUS.CONTINUE */:
442
+ case 100:
443
443
  return 'Continue';
444
- case 101 /* HTTP_STATUS.SWITCHING_PROTOCOL */:
444
+ case 101:
445
445
  return 'Switching Protocol';
446
- case 102 /* HTTP_STATUS.PROCESSING */:
446
+ case 102:
447
447
  return 'Processing';
448
- case 103 /* HTTP_STATUS.EARLY_HINTS */:
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 /* HTTP_STATUS.OK */:
454
+ case 200:
455
455
  return 'OK';
456
- case 201 /* HTTP_STATUS.CREATED */:
456
+ case 201:
457
457
  return 'Created';
458
- case 202 /* HTTP_STATUS.ACCEPTED */:
458
+ case 202:
459
459
  return 'Accepted';
460
- case 203 /* HTTP_STATUS.NON_AUTHORITATIVE_INFORMATION */:
460
+ case 203:
461
461
  return 'Non-Authoritative Information';
462
- case 204 /* HTTP_STATUS.NO_CONTENT */:
462
+ case 204:
463
463
  return 'No Content';
464
- case 205 /* HTTP_STATUS.RESET_CONTENT */:
464
+ case 205:
465
465
  return 'Reset Content';
466
- case 206 /* HTTP_STATUS.PARTIAL_CONTENT */:
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 /* HTTP_STATUS.MULTIPLE_CHOICES */:
472
+ case 300:
473
473
  return 'Multiple Choice';
474
- case 301 /* HTTP_STATUS.MOVED_PERMANENTLY */:
474
+ case 301:
475
475
  return 'Moved Permanently';
476
- case 302 /* HTTP_STATUS.FOUND */:
476
+ case 302:
477
477
  return 'Found';
478
- case 303 /* HTTP_STATUS.SEE_OTHER */:
478
+ case 303:
479
479
  return 'See Other';
480
- case 304 /* HTTP_STATUS.NOT_MODIFIED */:
480
+ case 304:
481
481
  return 'Not Modified';
482
- case 305 /* HTTP_STATUS.USE_PROXY */:
482
+ case 305:
483
483
  return 'Use Proxy';
484
- case 307 /* HTTP_STATUS.TEMPORARY_REDIRECT */:
484
+ case 307:
485
485
  return 'Temporary Redirect';
486
- case 308 /* HTTP_STATUS.PERMANENT_REDIRECT */:
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 /* HTTP_STATUS.BAD_REQUEST */:
492
+ case 400:
493
493
  return 'Bad Request';
494
- case 401 /* HTTP_STATUS.UNAUTHORIZED */:
494
+ case 401:
495
495
  return 'Upgrade Required';
496
- case 402 /* HTTP_STATUS.PAYMENT_REQUIRED */:
496
+ case 402:
497
497
  return 'Payment Required';
498
- case 403 /* HTTP_STATUS.FORBIDDEN */:
498
+ case 403:
499
499
  return 'Forbidden';
500
- case 404 /* HTTP_STATUS.NOT_FOUND */:
500
+ case 404:
501
501
  return 'Not Found';
502
- case 405 /* HTTP_STATUS.METHOD_NOT_ALLOWED */:
502
+ case 405:
503
503
  return 'Method Not Allowed';
504
- case 406 /* HTTP_STATUS.NOT_ACCEPTABLE */:
504
+ case 406:
505
505
  return 'Not Acceptable';
506
- case 407 /* HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED */:
506
+ case 407:
507
507
  return 'Proxy Authentication Required';
508
- case 408 /* HTTP_STATUS.REQUEST_TIMEOUT */:
508
+ case 408:
509
509
  return 'Request Timeout';
510
- case 409 /* HTTP_STATUS.CONFLICT */:
510
+ case 409:
511
511
  return 'Conflict';
512
- case 410 /* HTTP_STATUS.GONE */:
512
+ case 410:
513
513
  return 'Gone';
514
- case 411 /* HTTP_STATUS.LENGTH_REQUIRED */:
514
+ case 411:
515
515
  return 'Length Required';
516
- case 412 /* HTTP_STATUS.PRECONDITION_FAILED */:
516
+ case 412:
517
517
  return 'Precondition Failed';
518
- case 413 /* HTTP_STATUS.PAYLOAD_TOO_LARGE */:
518
+ case 413:
519
519
  return 'Payload Too Large';
520
- case 414 /* HTTP_STATUS.REQUEST_URI_TOO_LONG */:
520
+ case 414:
521
521
  return 'URI Too Long';
522
- case 415 /* HTTP_STATUS.UNSUPPORTED_MEDIA_TYPE */:
522
+ case 415:
523
523
  return 'Unsupported Media Type';
524
- case 416 /* HTTP_STATUS.RANGE_NOT_SATISFIABLE */:
524
+ case 416:
525
525
  return 'Range Not Satisfiable';
526
- case 417 /* HTTP_STATUS.EXPECTATION_FAILED */:
526
+ case 417:
527
527
  return 'Expectation Failed';
528
- case 421 /* HTTP_STATUS.MISDIRECTED_REQUEST */:
528
+ case 421:
529
529
  return 'Misdirected Request';
530
- case 422 /* HTTP_STATUS.UNPROCESSABLE_ENTITY */:
530
+ case 422:
531
531
  return 'Unprocessable Entity';
532
- case 423 /* HTTP_STATUS.LOCKED */:
532
+ case 423:
533
533
  return 'Locked';
534
- case 424 /* HTTP_STATUS.FAILED_DEPENDENCY */:
534
+ case 424:
535
535
  return 'Failed Dependency';
536
- case 425 /* HTTP_STATUS.TOO_EARLY */:
536
+ case 425:
537
537
  return 'Too Early';
538
- case 426 /* HTTP_STATUS.UPGRADE_REQUIRED */:
538
+ case 426:
539
539
  return 'Upgrade Required';
540
- case 428 /* HTTP_STATUS.PRECONDITION_REQUIRED */:
540
+ case 428:
541
541
  return 'Precondition Required';
542
- case 429 /* HTTP_STATUS.TOO_MANY_REQUESTS */:
542
+ case 429:
543
543
  return 'Too Many Requests';
544
- case 431 /* HTTP_STATUS.REQUEST_HEADER_FIELDS_TOO_LARGE */:
544
+ case 431:
545
545
  return 'Request Header Fields Too Large';
546
- case 451 /* HTTP_STATUS.UNAVAILABLE_FOR_LEGAL_REASONS */:
546
+ case 451:
547
547
  return 'Unavailable For Legal Reasons';
548
548
  }
549
549
  }
550
550
  else {
551
551
  switch (value) {
552
- case 500 /* HTTP_STATUS.INTERNAL_SERVER_ERROR */:
552
+ case 500:
553
553
  return 'Internal Server Error';
554
- case 501 /* HTTP_STATUS.NOT_IMPLEMENTED */:
554
+ case 501:
555
555
  return 'Not Implemented';
556
- case 502 /* HTTP_STATUS.BAD_GATEWAY */:
556
+ case 502:
557
557
  return 'Bad Gateway';
558
- case 503 /* HTTP_STATUS.SERVICE_UNAVAILABLE */:
558
+ case 503:
559
559
  return 'Service Unavailable';
560
- case 504 /* HTTP_STATUS.GATEWAY_TIMEOUT */:
560
+ case 504:
561
561
  return 'Gateway Timeout';
562
- case 505 /* HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED */:
562
+ case 505:
563
563
  return 'HTTP Version Not Supported';
564
- case 506 /* HTTP_STATUS.VARIANT_ALSO_NEGOTIATES */:
564
+ case 506:
565
565
  return 'Variant Also Negotiates';
566
- case 507 /* HTTP_STATUS.INSUFFICIENT_STORAGE */:
566
+ case 507:
567
567
  return 'Insufficient Storage';
568
- case 508 /* HTTP_STATUS.LOOP_DETECTED */:
568
+ case 508:
569
569
  return 'Loop Detected';
570
- case 509 /* HTTP_STATUS.BANDWIDTH_LIMIT_EXCEEDED */:
570
+ case 509:
571
571
  return 'Bandwidth Limit Exceeded';
572
- case 510 /* HTTP_STATUS.NOT_EXTENDED */:
572
+ case 510:
573
573
  return 'Not Extended';
574
- case 511 /* HTTP_STATUS.NETWORK_AUTHENTICATION_REQUIRED */:
574
+ case 511:
575
575
  return 'Network Authentication Required';
576
576
  }
577
577
  }
578
- return "Unknown" /* ERR_MESSAGE.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" /* VALUES.MODULE */;
635
+ this._moduleName = "request";
636
636
  this._threadable = true;
637
637
  this._config = {
638
- timeout: 60000 /* TIME.m */,
639
- connectTimeout: 20 * 1000 /* TIME.S */,
638
+ timeout: 60000,
639
+ connectTimeout: 20 * 1000,
640
640
  redirectLimit: 10,
641
- retryWait: 1000 /* TIME.S */,
642
- retryAfter: 30 * 1000 /* TIME.S */,
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 /* LOG_TYPE.HTTP */, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
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);
@@ -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 /* TIME.S */);
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);
@@ -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" /* VALUES.ARIA2 */, "Binary not found" /* ERR_MESSAGE.NOTFOUND_BINARY */));
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" /* VALUES.ARIA2 */, "Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, 'pathname'));
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" /* VALUES.ARIA2 */, "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, pathname));
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" /* VALUES.ARIA2 */, "Path is not a directory" /* ERR_MESSAGE.NOT_DIRECTORY */, pathname));
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 /* LOG_TYPE.STDOUT */)) {
1238
- this.formatMessage(32768 /* LOG_TYPE.STDOUT */, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
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" /* VALUES.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" /* ERR_MESSAGE.DELETE_FILE */, path.basename(file)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false }));
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" /* VALUES.ARIA2 */, uri, startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
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" /* VALUES.ARIA2 */, uri);
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" /* ERR_MESSAGE.UNKNOWN */, 'Exit status: ' + code));
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 /* LOG_TYPE.TIME_ELAPSED */ && current.title === "aria2" /* VALUES.ARIA2 */;
1332
+ progressBar = current?.type === 128 && current.title === "aria2";
1333
1333
  }
1334
- this.formatMessage(128 /* LOG_TYPE.TIME_ELAPSED */, "aria2" /* VALUES.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 });
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 /* TIME.S */);
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 /* HTTP_STATUS.PARTIAL_CONTENT */:
1422
- request.emit('error', (0, types_1.errorValue)("Aborted" /* ERR_MESSAGE.ABORTED */, 'Partial content'));
1423
- case 204 /* HTTP_STATUS.NO_CONTENT */:
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 /* CONSTANTS.MAX_FRAME_SIZE */, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
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 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
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" /* ERR_MESSAGE.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 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
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" /* ERR_MESSAGE.ABORTED_PROCESS */)), { once: true });
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" /* MIME.MULTIPART */)) {
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" /* MIME.MULTIPART */ || contentType === '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" /* MIME.MULTIPART */ + `; boundary="${boundary}"`;
1727
+ contentType = "multipart/form-data" + `; boundary="${boundary}"`;
1728
1728
  let contentLength = 0;
1729
1729
  const createPart = (name, filename, type) => {
1730
- const form = ["--" /* FORM_DATA.BOUNDARY_HASH */ + boundary, `Content-Disposition: form-data; name="${escapeQuote(name)}"` + (filename ? `; filename="${escapeQuote(filename)}"` : ''), "\r\n" /* FORM_DATA.CRLF */];
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" /* FORM_DATA.CRLF */);
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" /* FORM_DATA.CRLF */;
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" /* ERR_MESSAGE.UNKNOWN */, "multipart/form-data" /* MIME.MULTIPART */);
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" /* MIME.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" /* FORM_DATA.CRLF */);
1788
- contentLength += Buffer.byteLength(disposition) + target.length + 2 /* FORM_DATA.CRLF_LENGTH */;
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("--" /* FORM_DATA.BOUNDARY_HASH */ + boundary + "--" /* FORM_DATA.BOUNDARY_HASH */ + "\r\n" /* FORM_DATA.CRLF */);
1801
- headers['content-length'] = (contentLength + 38 /* FORM_DATA.BOUNDARY_LENGTH */).toString();
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" /* MIME.MULTIPART */));
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" /* MIME.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" /* MIME.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" /* MIME.TEXT */;
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 /* CONSTANTS.CHUNK_SIZE_LOCAL */ : 4096 /* CONSTANTS.CHUNK_SIZE */ });
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 /* HTTP_STATUS.MISDIRECTED_REQUEST */ || value === 505 /* HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED */;
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" /* ERR_MESSAGE.ABORTED */);
1885
- const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024 /* LOG_TYPE.HTTP */, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { titleBgColor: 'bgGrey', titleColor: 'yellow' });
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" /* ERR_MESSAGE.TIMEOUT */, href.toString()));
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 /* TIME.S */);
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 /* TIME.S */) + 'KiB/s';
1982
+ messageUnit = Math.ceil(unit * 1000) + 'KiB/s';
1983
1983
  }
1984
- else if (unit < 1000 /* TIME.S */) {
1984
+ else if (unit < 1000) {
1985
1985
  messageUnit = unit.toPrecision(3) + 'MiB/s';
1986
1986
  }
1987
1987
  else {
1988
- messageUnit = (unit / 1000 /* TIME.S */).toPrecision(3) + 'GiB/s';
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 /* LOG_TYPE.HTTP */);
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 /* LOG_TYPE.HTTP */, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: LOG_STDOUT });
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 /* LOG_TYPE.HTTP */, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
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 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2131
+ if (statusCode < 300) {
2132
2132
  acceptResponse(headers);
2133
2133
  }
2134
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
2134
+ else if (statusCode < 400) {
2135
2135
  redirectResponse(statusCode, headers.location);
2136
2136
  }
2137
- else if (statusCode === 401 /* HTTP_STATUS.UNAUTHORIZED */ ||
2138
- statusCode === 402 /* HTTP_STATUS.PAYMENT_REQUIRED */ ||
2139
- statusCode === 403 /* HTTP_STATUS.FORBIDDEN */ ||
2140
- statusCode === 404 /* HTTP_STATUS.NOT_FOUND */ ||
2141
- statusCode === 407 /* HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED */ ||
2142
- statusCode === 410 /* HTTP_STATUS.GONE */) {
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 /* QUERY_RESULT.OK */:
2182
+ case 1:
2183
2183
  errorResponse(err);
2184
2184
  break;
2185
- case 2 /* QUERY_RESULT.TIMEOUT */:
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 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2201
+ if (statusCode < 300) {
2202
2202
  acceptResponse(res.headers);
2203
2203
  }
2204
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
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 /* HTTP_STATUS.REQUEST_TIMEOUT */));
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" /* ERR_HTTP.HEADERS */, url.origin], err, { type: 1024 /* LOG_TYPE.HTTP */, abortable: this.abortable, fatal: false });
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" /* ERR_HTTP.HEADERS */, url.origin], err, { type: 1024 /* LOG_TYPE.HTTP */, abortable: this.abortable, fatal: false });
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.5",
3
+ "version": "0.8.7",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,11 +17,11 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
20
+ "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.8.5",
24
- "@e-mc/types": "0.8.5",
23
+ "@e-mc/module": "0.8.7",
24
+ "@e-mc/types": "0.8.7",
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("../module");
5
- const types_1 = require("../types");
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 /* HTTP_STATUS.REQUEST_TIMEOUT */:
91
- case 504 /* HTTP_STATUS.GATEWAY_TIMEOUT */:
92
- case 522 /* HTTP_STATUS.CONNECTION_TIMED_OUT */:
93
- case 524 /* HTTP_STATUS.A_TIMEOUT_OCCURRED */:
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 /* HTTP_STATUS.TOO_MANY_REQUESTS */:
98
- case 499 /* HTTP_STATUS.CLIENT_CLOSED_REQUEST */:
99
- case 500 /* HTTP_STATUS.INTERNAL_SERVER_ERROR */:
100
- case 502 /* HTTP_STATUS.BAD_GATEWAY */:
101
- case 503 /* HTTP_STATUS.SERVICE_UNAVAILABLE */:
102
- case 521 /* HTTP_STATUS.WEB_SERVER_IS_DOWN */:
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(parseInt(value) * 1000 /* TIME.S */);
141
+ return safeInt(parseInt(value) * 1000);
142
142
  case 'number':
143
- return safeInt(Math.trunc(value) * 1000 /* TIME.S */);
143
+ return safeInt(Math.trunc(value) * 1000);
144
144
  default:
145
145
  return NaN;
146
146
  }