@e-mc/request 0.12.9 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @e-mc/request
2
2
 
3
- * NodeJS 18
3
+ * NodeJS 18.20.5 LTS
4
4
  * ES2022
5
5
 
6
6
  ## General Usage
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.9/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.0/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -55,6 +55,7 @@ interface IRequest extends IModule {
55
55
  post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
56
56
  post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
57
57
  post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
58
+ get(uri: string | URL, format: "json" | "yaml" | "json5" | "xml" | "toml"): Promise<object | null>;
58
59
  get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
59
60
  detach(singleton?: boolean): void;
60
61
  reset(adapter?: IHttpAdapter): void;
@@ -74,10 +75,6 @@ interface RequestConstructor extends ModuleConstructor {
74
75
  readTLSKey(value: string, cache?: boolean): string;
75
76
  readTLSCert(value: string, cache?: boolean): string;
76
77
  isCert(value: string): boolean;
77
- /** @deprecated @e-mc/request/util */
78
- fromURL(url: URL, value: string): string;
79
- /** @deprecated @e-mc/request/util */
80
- fromStatusCode(value: number | string): string;
81
78
  defineHttpAgent(options: HttpAgentSettings): void;
82
79
  defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
83
80
  defineHttpAdapter(module: unknown): void;
@@ -255,9 +252,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
255
252
 
256
253
  ## References
257
254
 
258
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/http.d.ts
259
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/request.d.ts
260
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/settings.d.ts
255
+ - https://www.unpkg.com/@e-mc/types@0.13.0/lib/http.d.ts
256
+ - https://www.unpkg.com/@e-mc/types@0.13.0/lib/request.d.ts
257
+ - https://www.unpkg.com/@e-mc/types@0.13.0/lib/settings.d.ts
261
258
 
262
259
  * https://www.npmjs.com/package/@types/node
263
260
 
@@ -5,22 +5,28 @@ const yaml = require("js-yaml");
5
5
  const types_1 = require("@e-mc/types");
6
6
  const module_1 = require("@e-mc/module");
7
7
  const util_1 = require("@e-mc/request/util");
8
+ const kHttpAdapter = Symbol.for('request:http:adapter:constructor');
8
9
  let LOG_TIMEFORMAT = 'readable';
10
+ const isConstructor = (value) => typeof value === 'function' && !!value.prototype?.constructor.name;
9
11
  class HttpAdapter {
10
12
  instance;
11
13
  state;
12
14
  uri;
15
+ static [kHttpAdapter] = true;
16
+ static constructorOf(value) {
17
+ return isConstructor(value) && value[kHttpAdapter] === true;
18
+ }
13
19
  static isUnsupported(value) {
14
20
  return value === 421 || value === 505;
15
21
  }
16
22
  static isDowngrade(err) {
17
- return module_1.isErrorCode(err, 'ERR_HTTP2_ERROR') || err instanceof Error && this.isUnsupported(Math.abs(err.errno));
23
+ return (0, types_1.isErrorCode)(err, 'ERR_HTTP2_ERROR') || err instanceof Error && this.isUnsupported(Math.abs(err.errno));
18
24
  }
19
25
  static wasAborted(err) {
20
26
  return err instanceof Error && err.message.startsWith("Aborted");
21
27
  }
22
28
  static isConnectionError(err) {
23
- return module_1.isErrorCode(err, 'ETIMEDOUT', 'ECONNRESET');
29
+ return (0, types_1.isErrorCode)(err, 'ETIMEDOUT', 'ECONNRESET');
24
30
  }
25
31
  static defineHostConfig({ settings }) {
26
32
  const time_format = settings?.time_format;
package/index.js CHANGED
@@ -22,8 +22,8 @@ const host_1 = require("@e-mc/request/http/host");
22
22
  const adapter_1 = require("@e-mc/request/http/adapter");
23
23
  const kRequest = Symbol.for('request:constructor');
24
24
  const SUPPORTED_NODE20 = (0, types_1.supported)(20);
25
- const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) || (0, types_1.supported)(22, 15, 0, true);
26
- const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
25
+ const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) || (0, types_1.supported)(22, 15, true);
26
+ const SUPPORTED_PROXY = (0, types_1.supported)(24, 5);
27
27
  const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
28
28
  const REGEXP_RCLONE = /^rclone:\?/i;
29
29
  const HTTP = {
@@ -71,7 +71,12 @@ const RCLONE = {
71
71
  EXEC_GID: undefined,
72
72
  CHECK_FIRST: false,
73
73
  CHECKSUM: false,
74
+ COMBINED: '',
75
+ CSV: false,
74
76
  CUTOFF_MODE: '',
77
+ DIFFER: '',
78
+ ERROR: '',
79
+ HASH: '',
75
80
  IGNORE_CASE_SYNC: false,
76
81
  IGNORE_CHECKSUM: false,
77
82
  IGNORE_EXISTING: false,
@@ -91,8 +96,10 @@ const RCLONE = {
91
96
  NO_CHECK_DEST: false,
92
97
  NO_TRAVERSE: false,
93
98
  NO_UPDATE_DIR_MODTIME: false,
99
+ NO_UPDATE_MODTIME: false,
94
100
  REFRESH_TIMES: false,
95
101
  SIZE_ONLY: false,
102
+ STREAMING_UPLOAD_CUTOFF: '',
96
103
  UPDATE: false,
97
104
  FAST_LIST: false,
98
105
  BIND: '',
@@ -108,14 +115,6 @@ let READ_TIMEOUT = 0;
108
115
  let AGENT_TIMEOUT = 0;
109
116
  let LOG_HTTP = false;
110
117
  let LOG_TIMEPROCESS = true;
111
- let LIB_ZSTD = null;
112
- try {
113
- require('zstd-codec/lib/zstd-stream').run(codec => {
114
- LIB_ZSTD = codec;
115
- });
116
- }
117
- catch {
118
- }
119
118
  function getBaseHeaders(uri, headers) {
120
119
  let result;
121
120
  uri = (0, util_1.trimPath)(uri);
@@ -339,6 +338,16 @@ function checkEncoding(request, response, statusCode, outStream, contentEncoding
339
338
  return pipeTo;
340
339
  }
341
340
  }
341
+ function sendBody(request, options) {
342
+ const postData = options.postData;
343
+ if ((0, types_1.isString)(postData) || Buffer.isBuffer(postData)) {
344
+ request.write(postData);
345
+ }
346
+ else if (postData instanceof stream.Stream) {
347
+ postData.pipe(request);
348
+ }
349
+ request.end();
350
+ }
342
351
  function decompressEncoding(value, chunkSize) {
343
352
  switch (value) {
344
353
  case 'gzip':
@@ -350,9 +359,6 @@ function decompressEncoding(value, chunkSize) {
350
359
  case 'deflate-raw':
351
360
  return zlib.createInflateRaw({ chunkSize });
352
361
  case 'zstd':
353
- if (LIB_ZSTD) {
354
- return new LIB_ZSTD.ZstdDecompressTransform({ writableHighWaterMark: chunkSize });
355
- }
356
362
  if (SUPPORTED_ZSTD) {
357
363
  return zlib.createZstdDecompress({ chunkSize });
358
364
  }
@@ -490,7 +496,6 @@ function addAria2Proxy(args, protocol, host) {
490
496
  args.push(`--${protocol}-proxy-passwd="${escapeShellQuote(decodeURIComponent(password))}"`);
491
497
  }
492
498
  }
493
- const isConstructor = (value) => typeof value === 'function';
494
499
  const isDirEnd = (value) => value.endsWith('/') || value.endsWith(path.sep);
495
500
  const trimCharEnd = (value) => value.substring(0, value.length - 1);
496
501
  const configureDns = (family, options) => family === 0 ? options : { family, hints: family === 6 ? dns.V4MAPPED : 0 };
@@ -519,7 +524,8 @@ class Request extends module_1 {
519
524
  }
520
525
  const { request, download } = settings;
521
526
  if (download?.aria2) {
522
- let { update_status, max_concurrent_downloads, max_connection_per_server, check_integrity, bt_stop_timeout, bt_tracker_connect_timeout, bt_tracker_timeout, min_split_size, disk_cache, lowest_speed_limit, always_resume, file_allocation, proxy, no_proxy, conf_path } = download.aria2;
527
+ const aria2 = download.aria2;
528
+ let { update_status, check_integrity, bt_stop_timeout, min_split_size, disk_cache, lowest_speed_limit, always_resume, file_allocation, proxy, no_proxy, conf_path } = aria2;
523
529
  setBinExec(download.aria2, ARIA2);
524
530
  if ((0, types_1.isPlainObject)(update_status)) {
525
531
  const { interval, broadcast_only } = update_status;
@@ -534,21 +540,9 @@ class Request extends module_1 {
534
540
  if (typeof check_integrity === 'boolean') {
535
541
  ARIA2.CHECK_INTEGRITY = check_integrity;
536
542
  }
537
- if ((max_concurrent_downloads = (0, util_1.asInt)(max_concurrent_downloads)) > 0) {
538
- ARIA2.MAX_CONCURRENT_DOWNLOADS = max_concurrent_downloads;
539
- }
540
- if ((max_connection_per_server = (0, util_1.asInt)(max_connection_per_server)) > 0) {
541
- ARIA2.MAX_CONNECTION_PER_SERVER = max_connection_per_server;
542
- }
543
543
  if ((bt_stop_timeout = (0, util_1.asInt)(bt_stop_timeout)) >= 0) {
544
544
  ARIA2.BT_STOP_TIMEOUT = bt_stop_timeout;
545
545
  }
546
- if ((bt_tracker_connect_timeout = (0, util_1.asInt)(bt_tracker_connect_timeout)) > 0) {
547
- ARIA2.BT_TRACKER_CONNECT_TIMEOUT = bt_tracker_connect_timeout;
548
- }
549
- if ((bt_tracker_timeout = (0, util_1.asInt)(bt_tracker_timeout)) > 0) {
550
- ARIA2.BT_TRACKER_TIMEOUT = bt_tracker_timeout;
551
- }
552
546
  if (min_split_size = parseSize(min_split_size, false)) {
553
547
  ARIA2.MIN_SPLIT_SIZE = min_split_size;
554
548
  }
@@ -591,16 +585,17 @@ class Request extends module_1 {
591
585
  if (conf_path === '' || (0, types_1.isString)(conf_path) && this.isPath(conf_path = path.resolve(conf_path))) {
592
586
  ARIA2.CONF_PATH = conf_path;
593
587
  }
588
+ for (const name of ['max_concurrent_downloads', 'max_connection_per_server', 'bt_tracker_connect_timeout', 'bt_tracker_timeout']) {
589
+ let value = aria2[name];
590
+ if ((value = (0, util_1.asInt)(value)) > 0) {
591
+ ARIA2[name.toUpperCase()] = value;
592
+ }
593
+ }
594
594
  }
595
595
  if (download?.rclone) {
596
- let { check_first, checksum, cutoff_mode, ignore_case_sync, ignore_checksum, ignore_existing, ignore_size, ignore_times, immutable, inplace, max_backlog, max_duration, max_transfer, metadata, modify_window, multi_thread_chunk_size, multi_thread_cutoff, multi_thread_streams, multi_thread_write_buffer_size, no_check_dest, no_traverse, no_update_dir_modtime, refresh_times, size_only, update, fast_list, bind, contimeout, disable_http2, timeout, config } = download.rclone;
596
+ const rclone = download.rclone;
597
+ let { cutoff_mode, hash, max_backlog, max_duration, max_transfer, modify_window, multi_thread_chunk_size, multi_thread_cutoff, multi_thread_streams, multi_thread_write_buffer_size, streaming_upload_cutoff, bind, contimeout, timeout } = rclone;
597
598
  setBinExec(download.rclone, RCLONE);
598
- if (typeof check_first === 'boolean') {
599
- RCLONE.CHECK_FIRST = check_first;
600
- }
601
- if (typeof checksum === 'boolean') {
602
- RCLONE.CHECKSUM = checksum;
603
- }
604
599
  if ((0, types_1.isString)(cutoff_mode)) {
605
600
  const value = cutoff_mode.toUpperCase();
606
601
  switch (value) {
@@ -611,26 +606,18 @@ class Request extends module_1 {
611
606
  break;
612
607
  }
613
608
  }
614
- if (typeof ignore_case_sync === 'boolean') {
615
- RCLONE.IGNORE_CASE_SYNC = ignore_case_sync;
616
- }
617
- if (typeof ignore_checksum === 'boolean') {
618
- RCLONE.IGNORE_CHECKSUM = ignore_checksum;
619
- }
620
- if (typeof ignore_existing === 'boolean') {
621
- RCLONE.IGNORE_EXISTING = ignore_existing;
622
- }
623
- if (typeof ignore_size === 'boolean') {
624
- RCLONE.IGNORE_SIZE = ignore_size;
625
- }
626
- if (typeof ignore_times === 'boolean') {
627
- RCLONE.IGNORE_TIMES = ignore_times;
628
- }
629
- if (typeof immutable === 'boolean') {
630
- RCLONE.IMMUTABLE = immutable;
631
- }
632
- if (typeof inplace === 'boolean') {
633
- RCLONE.INPLACE = inplace;
609
+ if ((0, types_1.isString)(hash)) {
610
+ switch (hash.toLowerCase()) {
611
+ case 'md5':
612
+ RCLONE.HASH = 'md5';
613
+ break;
614
+ case 'sha-1':
615
+ RCLONE.HASH = 'SHA-1';
616
+ break;
617
+ case 'dropboxhash':
618
+ RCLONE.HASH = 'DropboxHash';
619
+ break;
620
+ }
634
621
  }
635
622
  if ((max_backlog = (0, util_1.asInt)(max_backlog)) > 0) {
636
623
  RCLONE.MAX_BACKLOG = max_backlog;
@@ -641,9 +628,6 @@ class Request extends module_1 {
641
628
  if (max_transfer = rcloneSize(max_transfer)) {
642
629
  RCLONE.MAX_TRANSFER = max_transfer;
643
630
  }
644
- if (typeof metadata === 'boolean') {
645
- RCLONE.METADATA = metadata;
646
- }
647
631
  if (modify_window = rcloneDuration(modify_window)) {
648
632
  RCLONE.MODIFY_WINDOW = modify_window;
649
633
  }
@@ -659,26 +643,8 @@ class Request extends module_1 {
659
643
  if (multi_thread_write_buffer_size = rcloneSize(multi_thread_write_buffer_size)) {
660
644
  RCLONE.MULTI_THREAD_WRITE_BUFFER_SIZE = multi_thread_write_buffer_size;
661
645
  }
662
- if (typeof no_check_dest === 'boolean') {
663
- RCLONE.NO_CHECK_DEST = no_check_dest;
664
- }
665
- if (typeof no_traverse === 'boolean') {
666
- RCLONE.NO_TRAVERSE = no_traverse;
667
- }
668
- if (typeof no_update_dir_modtime === 'boolean') {
669
- RCLONE.NO_UPDATE_DIR_MODTIME = no_update_dir_modtime;
670
- }
671
- if (typeof refresh_times === 'boolean') {
672
- RCLONE.REFRESH_TIMES = refresh_times;
673
- }
674
- if (typeof size_only === 'boolean') {
675
- RCLONE.SIZE_ONLY = size_only;
676
- }
677
- if (typeof update === 'boolean') {
678
- RCLONE.UPDATE = update;
679
- }
680
- if (typeof fast_list === 'boolean') {
681
- RCLONE.FAST_LIST = fast_list;
646
+ if (streaming_upload_cutoff = rcloneSize(streaming_upload_cutoff)) {
647
+ RCLONE.STREAMING_UPLOAD_CUTOFF = streaming_upload_cutoff;
682
648
  }
683
649
  if (contimeout = rcloneDuration(contimeout)) {
684
650
  RCLONE.CONTIMEOUT = contimeout;
@@ -686,14 +652,20 @@ class Request extends module_1 {
686
652
  if (typeof bind === 'string') {
687
653
  RCLONE.BIND = bind;
688
654
  }
689
- if (typeof disable_http2 === 'boolean') {
690
- RCLONE.DISABLE_HTTP2 = disable_http2;
691
- }
692
655
  if (timeout = rcloneDuration(timeout)) {
693
656
  RCLONE.TIMEOUT = timeout;
694
657
  }
695
- if (config === '' || (0, types_1.isString)(config) && this.isPath(config = path.resolve(config), true)) {
696
- RCLONE.CONFIG = config;
658
+ for (const name of ['check_first', 'checksum', 'csv', 'ignore_case_sync', 'ignore_checksum', 'ignore_existing', 'ignore_size', 'ignore_times', 'immutable', 'inplace', 'metadata', 'no_check_dest', 'no_traverse', 'no_update_dir_modtime', 'no_update_modtime', 'refresh_times', 'size_only', 'update', 'fast_list', 'disable_http2']) {
659
+ const value = rclone[name];
660
+ if (typeof value === 'boolean') {
661
+ RCLONE[name.toUpperCase()] = value;
662
+ }
663
+ }
664
+ for (const name of ['combined', 'differ', 'error', 'config']) {
665
+ let value = rclone[name];
666
+ if (value === '' || (0, types_1.isString)(value) && this.isPath(value = path.resolve(value), true)) {
667
+ RCLONE[name.toUpperCase()] = value;
668
+ }
697
669
  }
698
670
  }
699
671
  if (request) {
@@ -755,13 +727,7 @@ class Request extends module_1 {
755
727
  return this.readCACert(value, cache);
756
728
  }
757
729
  static isCert(value) {
758
- return typeof value === 'string' && (value = value.trim()).length > 0 && REGEXP_PEMCERT.test(value);
759
- }
760
- static fromURL(url, value) {
761
- return (0, util_1.fromURL)(url, value);
762
- }
763
- static fromStatusCode(value) {
764
- return (0, util_1.fromStatusCode)(value);
730
+ return typeof value === 'string' && (value = value.trim()).length > 0 && /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s.test(value);
765
731
  }
766
732
  static defineHttpAgent(options) {
767
733
  const { keepAlive, timeout = 0 } = options;
@@ -788,11 +754,21 @@ class Request extends module_1 {
788
754
  if (reset) {
789
755
  clearDnsLookup();
790
756
  }
791
- switch (family = (0, util_1.asInt)(family)) {
792
- case 0:
793
- case 4:
794
- case 6:
795
- DNS.FAMILY = family;
757
+ switch (family) {
758
+ case 'IPv4':
759
+ DNS.FAMILY = 4;
760
+ break;
761
+ case 'IPv6':
762
+ DNS.FAMILY = 6;
763
+ break;
764
+ default:
765
+ switch (family = (0, util_1.asInt)(family)) {
766
+ case 0:
767
+ case 4:
768
+ case 6:
769
+ DNS.FAMILY = family;
770
+ break;
771
+ }
796
772
  break;
797
773
  }
798
774
  if (expires !== undefined) {
@@ -804,14 +780,14 @@ class Request extends module_1 {
804
780
  }
805
781
  }
806
782
  for (const hostname in resolve) {
807
- let { address, family: ipv } = resolve[hostname];
808
- if (address && (ipv = ipv && ((ipv = +ipv) === 4 || ipv === 6) ? ipv : net.isIPv6(address) ? 6 : net.isIPv4(address) ? 4 : 0)) {
809
- DNS.CACHE[hostname] = [{ address, family: ipv }];
783
+ const { address, family: ipv } = resolve[hostname];
784
+ if (address && (family = (0, util_1.asInt)(ipv) && (family === 4 || family === 6) ? family : net.isIPv6(address) ? 6 : net.isIPv4(address) ? 4 : 0)) {
785
+ DNS.CACHE[hostname] = [{ address, family }];
810
786
  }
811
787
  }
812
788
  }
813
789
  static defineHttpAdapter(module) {
814
- if (isConstructor(module) && module.prototype instanceof adapter_1) {
790
+ if (adapter_1.constructorOf(module)) {
815
791
  HTTP_ADAPTER = module;
816
792
  }
817
793
  }
@@ -1233,7 +1209,7 @@ class Request extends module_1 {
1233
1209
  }
1234
1210
  else {
1235
1211
  ({ signal, silent } = options);
1236
- ({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file'], options.shellExpansion));
1212
+ ({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file']));
1237
1213
  }
1238
1214
  try {
1239
1215
  if (typeof uri === 'string' && module_1.isURL(uri)) {
@@ -1495,7 +1471,7 @@ class Request extends module_1 {
1495
1471
  }
1496
1472
  else {
1497
1473
  silent = options.silent;
1498
- ({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--interactive', '--dry-run'], ['–name-transform', '--partial-suffix', '--verbose'], options.shellExpansion));
1474
+ ({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--interactive', '--dry-run'], ['–name-transform', '--partial-suffix', '--verbose']));
1499
1475
  }
1500
1476
  const command = options.command || 'copy';
1501
1477
  let source;
@@ -1545,6 +1521,12 @@ class Request extends module_1 {
1545
1521
  if (RCLONE.CUTOFF_MODE) {
1546
1522
  opts.push('--cutoff-mode=' + RCLONE.CUTOFF_MODE);
1547
1523
  }
1524
+ if (RCLONE.CSV) {
1525
+ opts.push('--csv');
1526
+ }
1527
+ if (RCLONE.HASH) {
1528
+ opts.push('--hash=' + RCLONE.HASH);
1529
+ }
1548
1530
  if (RCLONE.IGNORE_CASE_SYNC) {
1549
1531
  opts.push('--ignore-case-sync');
1550
1532
  }
@@ -1602,12 +1584,18 @@ class Request extends module_1 {
1602
1584
  if (RCLONE.NO_UPDATE_DIR_MODTIME) {
1603
1585
  opts.push('--no-update-dir-modtime');
1604
1586
  }
1587
+ if (RCLONE.NO_UPDATE_MODTIME) {
1588
+ opts.push('--no-update-modtime');
1589
+ }
1605
1590
  if (RCLONE.REFRESH_TIMES) {
1606
1591
  opts.push('--refresh-times');
1607
1592
  }
1608
1593
  if (RCLONE.SIZE_ONLY) {
1609
1594
  opts.push('--size-only');
1610
1595
  }
1596
+ if (RCLONE.STREAMING_UPLOAD_CUTOFF) {
1597
+ opts.push('--streaming-upload-cutoff');
1598
+ }
1611
1599
  if (RCLONE.FAST_LIST) {
1612
1600
  opts.push('--fast-list');
1613
1601
  }
@@ -1629,6 +1617,15 @@ class Request extends module_1 {
1629
1617
  else if (this._config.timeout > 0) {
1630
1618
  opts.push(`--timeout=${this._config.timeout}ms`);
1631
1619
  }
1620
+ if (RCLONE.COMBINED) {
1621
+ opts.push(`--combined="${escapeShellQuote(RCLONE.COMBINED)}"`);
1622
+ }
1623
+ if (RCLONE.DIFFER) {
1624
+ opts.push(`--differ="${escapeShellQuote(RCLONE.DIFFER)}"`);
1625
+ }
1626
+ if (RCLONE.ERROR) {
1627
+ opts.push(`--error="${escapeShellQuote(RCLONE.ERROR)}"`);
1628
+ }
1632
1629
  if (RCLONE.CONFIG) {
1633
1630
  opts.push(`--config="${escapeShellQuote(RCLONE.CONFIG)}"`);
1634
1631
  }
@@ -1820,7 +1817,7 @@ class Request extends module_1 {
1820
1817
  const baseHeaders = this.headersOf(uri);
1821
1818
  let request, ca, cert, key, ciphers, minVersion;
1822
1819
  if (getting && this.acceptEncoding && !host.localhost && !baseHeaders?.['accept-encoding']) {
1823
- (headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD || SUPPORTED_ZSTD ? ', zstd' : '');
1820
+ (headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (SUPPORTED_ZSTD ? ', zstd' : '');
1824
1821
  }
1825
1822
  if (posting && options.postData) {
1826
1823
  if (expectContinue) {
@@ -1856,7 +1853,7 @@ class Request extends module_1 {
1856
1853
  request.on('response', response => {
1857
1854
  const statusCode = response[':status'];
1858
1855
  if (expectContinue) {
1859
- this.abortHeaders(url.href, request, options, statusCode, "Did not receive continue acknowledgment");
1856
+ this.abortHeaders(request, options, { href: url.href, statusCode, message: "Did not receive continue acknowledgment" });
1860
1857
  return;
1861
1858
  }
1862
1859
  connected = true;
@@ -1935,27 +1932,34 @@ class Request extends module_1 {
1935
1932
  if (!socketPath) {
1936
1933
  let { keepAlive, agentTimeout } = options;
1937
1934
  if (proxy) {
1935
+ keepAlive ??= proxy.keepAlive;
1936
+ agentTimeout ??= proxy.agentTimeout;
1937
+ const proxyHeaders = this.#headers && getBaseHeaders(proxy.host.href, this.#headers) || getBaseHeaders(proxy.host.href, HTTP.HEADERS);
1938
1938
  const pkg = secure ? 'https-proxy-agent' : 'http-proxy-agent';
1939
1939
  try {
1940
- keepAlive ??= proxy.keepAlive;
1941
- agentTimeout ??= proxy.agentTimeout;
1942
- const proxyHeaders = this.#headers && getBaseHeaders(proxy.host.href, this.#headers) || getBaseHeaders(proxy.host.href, HTTP.HEADERS);
1943
1940
  agent = require(pkg)(proxy.host, (typeof keepAlive === 'boolean' || agentTimeout > 0) && agentTimeout !== 0 ? { keepAlive: keepAlive ?? true, timeout: agentTimeout, headers: proxyHeaders } : { headers: proxyHeaders });
1944
1941
  }
1945
1942
  catch (err) {
1946
- this.checkPackage(err, pkg, "Unknown");
1943
+ if (!SUPPORTED_PROXY || proxyHeaders) {
1944
+ this.checkPackage(err, pkg, proxyHeaders ? "Unable to process headers" : '');
1945
+ }
1947
1946
  }
1948
1947
  }
1949
- else if (keepAlive === false) {
1950
- agent = new (secure ? https.Agent : http.Agent)({ keepAlive: false });
1951
- }
1952
- else if (keepAlive === true || agentTimeout > 0) {
1953
- agent = new (secure ? https.Agent : http.Agent)({ keepAlive: true, timeout: agentTimeout });
1954
- }
1955
- else if (agentTimeout !== 0) {
1956
- agentTimeout ??= this.agentTimeout;
1957
- if (this.keepAlive !== null || agentTimeout > 0) {
1958
- agent = new (secure ? https.Agent : http.Agent)({ keepAlive: this.keepAlive ?? true, timeout: agentTimeout });
1948
+ if (!agent) {
1949
+ let proxyEnv;
1950
+ if (proxy && SUPPORTED_PROXY) {
1951
+ const http_proxy = proxy.host.toString();
1952
+ proxyEnv = { http_proxy, https_proxy: http_proxy };
1953
+ }
1954
+ if (keepAlive === false) {
1955
+ agent = new (secure ? https.Agent : http.Agent)({ keepAlive: false, proxyEnv });
1956
+ }
1957
+ else if (keepAlive === true || agentTimeout > 0) {
1958
+ agent = new (secure ? https.Agent : http.Agent)({ keepAlive: true, timeout: agentTimeout, proxyEnv });
1959
+ }
1960
+ else if (agentTimeout !== 0 || proxyEnv) {
1961
+ agentTimeout ??= this.agentTimeout;
1962
+ agent = new (secure ? https.Agent : http.Agent)({ keepAlive: this.keepAlive ?? true, timeout: agentTimeout || undefined, proxyEnv });
1959
1963
  }
1960
1964
  }
1961
1965
  }
@@ -2051,7 +2055,7 @@ class Request extends module_1 {
2051
2055
  request.emit('end');
2052
2056
  });
2053
2057
  if (expectContinue) {
2054
- this.abortHeaders(url.href, request, options, statusCode, "Did not receive continue acknowledgment");
2058
+ this.abortHeaders(request, options, { href: url.href, statusCode, message: "Did not receive continue acknowledgment" });
2055
2059
  return;
2056
2060
  }
2057
2061
  }
@@ -2078,17 +2082,6 @@ class Request extends module_1 {
2078
2082
  ac.abort(new Error("Aborted by process"));
2079
2083
  }, { once: true });
2080
2084
  }
2081
- const sendBody = () => {
2082
- if (posting) {
2083
- const postData = options.postData;
2084
- if ((0, types_1.isString)(postData) || Buffer.isBuffer(postData)) {
2085
- request.write(postData);
2086
- }
2087
- else if (postData instanceof stream.Stream) {
2088
- postData.pipe(request);
2089
- }
2090
- }
2091
- };
2092
2085
  if (expectContinue) {
2093
2086
  const pending = setTimeout(() => {
2094
2087
  request.end();
@@ -2096,12 +2089,18 @@ class Request extends module_1 {
2096
2089
  request.on('continue', () => {
2097
2090
  clearTimeout(pending);
2098
2091
  expectContinue = false;
2099
- sendBody();
2100
- request.end();
2092
+ if (posting) {
2093
+ sendBody(request, options);
2094
+ }
2095
+ else {
2096
+ request.end();
2097
+ }
2101
2098
  });
2102
2099
  }
2100
+ else if (posting) {
2101
+ sendBody(request, options);
2102
+ }
2103
2103
  else {
2104
- sendBody();
2105
2104
  request.end();
2106
2105
  }
2107
2106
  return request;
@@ -2198,7 +2197,7 @@ class Request extends module_1 {
2198
2197
  type ||= module_1.lookupMime(filename);
2199
2198
  target = fs.readFileSync(target);
2200
2199
  }
2201
- else if (target instanceof stream.Readable) {
2200
+ else if (stream.Readable.isReadable(target)) {
2202
2201
  const chunks = [];
2203
2202
  for await (const chunk of target) {
2204
2203
  chunks.push(chunk);
@@ -2323,7 +2322,7 @@ class Request extends module_1 {
2323
2322
  for (const callback of called) {
2324
2323
  try {
2325
2324
  if (callback(code, headers, url) === true) {
2326
- this.abortHeaders(href, request, options, code);
2325
+ this.abortHeaders(request, options, { href, statusCode: code });
2327
2326
  return false;
2328
2327
  }
2329
2328
  }
@@ -2355,7 +2354,7 @@ class Request extends module_1 {
2355
2354
  for (const [callback, data] of called) {
2356
2355
  try {
2357
2356
  if (callback(data, url) === true) {
2358
- this.abortHeaders(href, request, options);
2357
+ this.abortHeaders(request, options, { href });
2359
2358
  return false;
2360
2359
  }
2361
2360
  }
@@ -2366,7 +2365,7 @@ class Request extends module_1 {
2366
2365
  }
2367
2366
  return true;
2368
2367
  }
2369
- abortHeaders(href, request, options, statusCode = '', message = "Aborted by client") {
2368
+ abortHeaders(request, options, { href, statusCode = '', message = "Aborted by client" } = {}) {
2370
2369
  const reason = (0, types_1.errorMessage)(statusCode, message, href);
2371
2370
  const outAbort = options.outAbort;
2372
2371
  if (outAbort) {
@@ -2375,7 +2374,7 @@ class Request extends module_1 {
2375
2374
  }
2376
2375
  request.destroy(reason);
2377
2376
  }
2378
- parseBinOpts(options, ignore, skip, doubleQuote = false) {
2377
+ parseBinOpts(options, ignore, skip, doubleQuote = options.shellExpansion) {
2379
2378
  let pathname = options.pathname, binOpts;
2380
2379
  if (pathname instanceof URL) {
2381
2380
  pathname = (0, node_url_1.fileURLToPath)(pathname);
@@ -2439,7 +2438,7 @@ class Request extends module_1 {
2439
2438
  return { pathname, headers: (0, util_1.parseOutgoingHeaders)(options.headers), binOpts };
2440
2439
  }
2441
2440
  set adapter(value) {
2442
- if (isConstructor(value) && value.prototype instanceof adapter_1) {
2441
+ if (adapter_1.constructorOf(value)) {
2443
2442
  this.#adapter = value;
2444
2443
  }
2445
2444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.12.9",
3
+ "version": "0.13.0",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/module": "0.12.9",
23
- "@e-mc/types": "0.12.9",
22
+ "@e-mc/module": "0.13.0",
23
+ "@e-mc/types": "0.13.0",
24
24
  "combined-stream": "^1.0.8",
25
25
  "js-yaml": "^4.1.0",
26
26
  "picomatch": "^4.0.3",
package/util.js CHANGED
@@ -142,7 +142,7 @@ function isRetryable(value, timeout) {
142
142
  }
143
143
  function parseHttpProxy(value, ignoreEnv) {
144
144
  if (!ignoreEnv) {
145
- value ||= process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
145
+ value ||= process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.ALL_PROXY;
146
146
  }
147
147
  if (value) {
148
148
  try {
@@ -426,7 +426,7 @@ function cleanupStream(stream, uri) {
426
426
  }
427
427
  }
428
428
  catch (err) {
429
- if (!module_1.isErrorCode(err, 'ENOENT')) {
429
+ if (!(0, types_1.isErrorCode)(err, 'ENOENT')) {
430
430
  module_1.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
431
431
  }
432
432
  }