@e-mc/request 0.7.19 → 0.7.20
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/http/adapter/index.js +28 -23
- package/index.js +2 -1
- package/package.json +3 -3
package/http/adapter/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
@@ -1692,7 +1692,7 @@ class Request extends module_1.default {
|
|
|
1692
1692
|
else {
|
|
1693
1693
|
options = {};
|
|
1694
1694
|
}
|
|
1695
|
-
const headers = (0, util_1.parseOutgoingHeaders)(options.headers ||
|
|
1695
|
+
const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
|
|
1696
1696
|
for (const attr in headers) {
|
|
1697
1697
|
const name = attr.toLowerCase();
|
|
1698
1698
|
if (name === 'content-type' || name === 'content-length') {
|
|
@@ -1806,6 +1806,7 @@ class Request extends module_1.default {
|
|
|
1806
1806
|
options.httpVersion = 1;
|
|
1807
1807
|
options.postData = data;
|
|
1808
1808
|
headers['content-type'] = contentType || "text/plain";
|
|
1809
|
+
options.headers = headers;
|
|
1809
1810
|
return this.get(uri, options);
|
|
1810
1811
|
}
|
|
1811
1812
|
async get(uri, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.20",
|
|
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": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.7.
|
|
24
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/module": "0.7.20",
|
|
24
|
+
"@e-mc/types": "0.7.20",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"which": "^2.0.2"
|