@e-mc/request 0.10.8 → 0.10.9

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.10.8/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.9/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -205,9 +205,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
205
205
 
206
206
  ## References
207
207
 
208
- - https://www.unpkg.com/@e-mc/types@0.10.8/lib/http.d.ts
209
- - https://www.unpkg.com/@e-mc/types@0.10.8/lib/request.d.ts
210
- - https://www.unpkg.com/@e-mc/types@0.10.8/lib/settings.d.ts
208
+ - https://www.unpkg.com/@e-mc/types@0.10.9/lib/http.d.ts
209
+ - https://www.unpkg.com/@e-mc/types@0.10.9/lib/request.d.ts
210
+ - https://www.unpkg.com/@e-mc/types@0.10.9/lib/settings.d.ts
211
211
 
212
212
  * https://www.npmjs.com/package/@types/node
213
213
 
@@ -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
@@ -2360,7 +2360,7 @@ class Request extends module_1 {
2360
2360
  else {
2361
2361
  options = {};
2362
2362
  }
2363
- const headers = (0, util_1.parseOutgoingHeaders)(options.headers ||= {});
2363
+ const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
2364
2364
  for (const attr in headers) {
2365
2365
  const name = attr.toLowerCase();
2366
2366
  if (name === 'content-type' || name === 'content-length') {
@@ -2470,6 +2470,7 @@ class Request extends module_1 {
2470
2470
  options.httpVersion = 1;
2471
2471
  options.postData = data;
2472
2472
  headers['content-type'] = contentType || "text/plain";
2473
+ options.headers = headers;
2473
2474
  return this.get(uri, options);
2474
2475
  }
2475
2476
  async get(uri, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
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.10.8",
24
- "@e-mc/types": "0.10.8",
23
+ "@e-mc/module": "0.10.9",
24
+ "@e-mc/types": "0.10.9",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^4.0.2",