@e-mc/request 0.9.17 → 0.9.18

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
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.17/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.18/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -202,9 +202,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
202
202
 
203
203
  ## References
204
204
 
205
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/http.d.ts
206
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/request.d.ts
207
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/settings.d.ts
205
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/http.d.ts
206
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/request.d.ts
207
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/settings.d.ts
208
208
 
209
209
  * https://www.npmjs.com/package/@types/node
210
210
 
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
- var _a;
3
2
  const fs = require("node:fs");
4
3
  const http2 = require("node:http2");
5
4
  const yaml = require("js-yaml");
6
5
  const types_1 = require("@e-mc/types");
7
6
  const module_1 = require("@e-mc/module");
8
7
  const util_1 = require("@e-mc/request/util");
9
- const kOutStream = Symbol('outStream');
10
- const kOptions = Symbol('options');
11
8
  let LOG_TIMEFORMAT = 'readable';
12
9
  class HttpAdapter {
10
+ instance;
11
+ state;
12
+ uri;
13
13
  static isUnsupported(value) {
14
14
  return value === 421 || value === 505;
15
15
  }
@@ -38,20 +38,26 @@ class HttpAdapter {
38
38
  break;
39
39
  }
40
40
  }
41
+ contentLength = 0;
42
+ retries = 0;
43
+ redirects = 0;
44
+ closed = false;
45
+ aborted = false;
46
+ timeout = null;
47
+ dataTime = null;
48
+ delayTime = undefined;
49
+ opts;
50
+ client;
51
+ resolve;
52
+ reject;
53
+ startTime;
54
+ #outStream = null;
55
+ #options;
41
56
  constructor(instance, state, uri, options) {
42
57
  this.instance = instance;
43
58
  this.state = state;
44
59
  this.uri = uri;
45
- this.contentLength = 0;
46
- this.retries = 0;
47
- this.redirects = 0;
48
- this.closed = false;
49
- this.aborted = false;
50
- this.timeout = null;
51
- this.dataTime = null;
52
- this.delayTime = undefined;
53
- this[_a] = null;
54
- this[kOptions] = options;
60
+ this.#options = options;
55
61
  this.startTime = state.log ? process.hrtime.bigint() : BigInt(0);
56
62
  this.setOpts();
57
63
  }
@@ -91,14 +97,14 @@ class HttpAdapter {
91
97
  this.retryResponse(statusCode, headers['retry-after']);
92
98
  }
93
99
  else if (HttpAdapter.isUnsupported(statusCode)) {
94
- this.retryDownload(true, this.formatNgFlags(http2.constants.NGHTTP2_PROTOCOL_ERROR, statusCode));
100
+ this.retryDownload(true, this.#formatNgFlags(http2.constants.NGHTTP2_PROTOCOL_ERROR, statusCode));
95
101
  }
96
102
  else {
97
103
  switch (flags) {
98
104
  case http2.constants.NGHTTP2_PROTOCOL_ERROR:
99
105
  case http2.constants.NGHTTP2_INADEQUATE_SECURITY:
100
106
  case http2.constants.NGHTTP2_HTTP_1_1_REQUIRED:
101
- this.retryDownload(true, this.formatNgFlags(flags, statusCode, headers.location));
107
+ this.retryDownload(true, this.#formatNgFlags(flags, statusCode, headers.location));
102
108
  break;
103
109
  default:
104
110
  this.retryDownload(false, this.formatStatus(statusCode));
@@ -186,7 +192,7 @@ class HttpAdapter {
186
192
  if (uri) {
187
193
  this.uri = uri;
188
194
  }
189
- this.opts = this.instance.opts(this.uri, this[kOptions]);
195
+ this.opts = this.instance.opts(this.uri, this.#options);
190
196
  }
191
197
  setWriteStream() {
192
198
  const pipeTo = this.pipeTo;
@@ -454,7 +460,7 @@ class HttpAdapter {
454
460
  return;
455
461
  }
456
462
  }
457
- this.sendWarning(this.formatRetry((0, util_1.fromStatusCode)(statusCode)));
463
+ this.sendWarning(this.#formatRetry((0, util_1.fromStatusCode)(statusCode)));
458
464
  if ((0, util_1.isRetryable)(statusCode, true)) {
459
465
  setImmediate(this.init.bind(this));
460
466
  }
@@ -468,7 +474,7 @@ class HttpAdapter {
468
474
  return (0, util_1.isRetryable)(value) && ++this.retries <= this.retryLimit;
469
475
  }
470
476
  retryTimeout() {
471
- this.sendWarning(this.formatRetry("HTTP connection timeout"));
477
+ this.sendWarning(this.#formatRetry("HTTP connection timeout"));
472
478
  this.init();
473
479
  }
474
480
  terminate(err) {
@@ -501,10 +507,10 @@ class HttpAdapter {
501
507
  this.outStream = null;
502
508
  }
503
509
  }
504
- formatNgFlags(value, statusCode, location) {
510
+ #formatNgFlags(value, statusCode, location) {
505
511
  return location ? `Using HTTP 1.1 for URL redirect (${location})` : this.formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
506
512
  }
507
- formatRetry(message) {
513
+ #formatRetry(message) {
508
514
  return `${message} (${this.retries} / ${this.retryLimit})`;
509
515
  }
510
516
  set abortController(value) {
@@ -514,13 +520,13 @@ class HttpAdapter {
514
520
  return this.opts.outAbort || null;
515
521
  }
516
522
  set outStream(value) {
517
- this[kOutStream] = value;
523
+ this.#outStream = value;
518
524
  if (value) {
519
525
  this.opts.outStream = value;
520
526
  }
521
527
  }
522
528
  get outStream() {
523
- return this[kOutStream];
529
+ return this.#outStream;
524
530
  }
525
531
  get destroyed() {
526
532
  return this.client.destroyed || this.httpVersion === 2 && this.client.aborted;
@@ -550,5 +556,4 @@ class HttpAdapter {
550
556
  return this.state.config.redirectLimit;
551
557
  }
552
558
  }
553
- _a = kOutStream;
554
559
  module.exports = HttpAdapter;
package/index.js CHANGED
@@ -1763,7 +1763,7 @@ class Request extends module_1 {
1763
1763
  else {
1764
1764
  options = {};
1765
1765
  }
1766
- const headers = (0, util_1.parseOutgoingHeaders)(options.headers ||= {});
1766
+ const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
1767
1767
  for (const attr in headers) {
1768
1768
  const name = attr.toLowerCase();
1769
1769
  if (name === 'content-type' || name === 'content-length') {
@@ -1879,6 +1879,7 @@ class Request extends module_1 {
1879
1879
  options.httpVersion = 1;
1880
1880
  options.postData = data;
1881
1881
  headers['content-type'] = contentType || "text/plain";
1882
+ options.headers = headers;
1882
1883
  return this.get(uri, options);
1883
1884
  }
1884
1885
  async get(uri, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.9.17",
3
+ "version": "0.9.18",
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.9.17",
24
- "@e-mc/types": "0.9.17",
23
+ "@e-mc/module": "0.9.18",
24
+ "@e-mc/types": "0.9.18",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^4.0.2",