@e-mc/request 0.7.3 → 0.7.5
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 +1 -1
- package/http/host/index.js +2 -1
- package/index.js +36 -27
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
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:
|
|
4
4
|
|
package/http/host/index.js
CHANGED
|
@@ -154,6 +154,7 @@ class HttpHost {
|
|
|
154
154
|
return ++data[2];
|
|
155
155
|
}
|
|
156
156
|
upgrade(version, altSvc) {
|
|
157
|
+
var _e;
|
|
157
158
|
if (altSvc && this.secure) {
|
|
158
159
|
if (altSvc === 'clear') {
|
|
159
160
|
this.clearAltSvc();
|
|
@@ -187,7 +188,7 @@ class HttpHost {
|
|
|
187
188
|
break;
|
|
188
189
|
}
|
|
189
190
|
const address = match[1] || hostname;
|
|
190
|
-
const ma = +(/ma=(\d+)/.exec(match[3])
|
|
191
|
+
const ma = +(((_e = /ma=(\d+)/.exec(match[3])) === null || _e === void 0 ? void 0 : _e[1]) || 86400);
|
|
191
192
|
if (!excluded.includes(`h${i + 1}:${address}:${port}`)) {
|
|
192
193
|
addresses.push([
|
|
193
194
|
address,
|
package/index.js
CHANGED
|
@@ -133,7 +133,7 @@ function setOutgoingHeaders(output, headers) {
|
|
|
133
133
|
}
|
|
134
134
|
function getProxySettings(request, agentTimeout) {
|
|
135
135
|
const proxy = request.proxy;
|
|
136
|
-
if (proxy
|
|
136
|
+
if ((proxy === null || proxy === void 0 ? void 0 : proxy.address) && proxy.port) {
|
|
137
137
|
const port = (0, util_1.asInt)(proxy.port);
|
|
138
138
|
const address = (!module_1.default.isURL(proxy.address) ? port === 80 ? 'http://' : 'https://' : '') + proxy.address;
|
|
139
139
|
try {
|
|
@@ -272,6 +272,7 @@ class Request extends module_1.default {
|
|
|
272
272
|
return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
|
|
273
273
|
}
|
|
274
274
|
static loadSettings(settings, password) {
|
|
275
|
+
var _l;
|
|
275
276
|
if (!this.enabled("process.password") || super.loadSettings({ process: settings.process }, password)) {
|
|
276
277
|
const { request, download } = settings;
|
|
277
278
|
if (download && (0, types_1.isPlainObject)(download.aria2)) {
|
|
@@ -388,7 +389,7 @@ class Request extends module_1.default {
|
|
|
388
389
|
[TLS.TEXT, TLS.FILE] = validateCerts(certs);
|
|
389
390
|
}
|
|
390
391
|
HTTP.PROXY = getProxySettings(request, agent_timeout);
|
|
391
|
-
const time_format = request.settings
|
|
392
|
+
const time_format = (_l = request.settings) === null || _l === void 0 ? void 0 : _l.time_format;
|
|
392
393
|
switch (time_format) {
|
|
393
394
|
case 'readable':
|
|
394
395
|
case 'relative':
|
|
@@ -611,6 +612,7 @@ class Request extends module_1.default {
|
|
|
611
612
|
return ARIA2.BIN;
|
|
612
613
|
}
|
|
613
614
|
constructor(data) {
|
|
615
|
+
var _l;
|
|
614
616
|
super();
|
|
615
617
|
this.startTime = Date.now();
|
|
616
618
|
this.readExpect = 'none';
|
|
@@ -640,13 +642,13 @@ class Request extends module_1.default {
|
|
|
640
642
|
const timeout = (0, util_1.fromSeconds)(data.timeout);
|
|
641
643
|
let value;
|
|
642
644
|
this.readTimeout = (value = (0, util_1.fromSeconds)(read_timeout)) >= 0 ? value : READ_TIMEOUT;
|
|
643
|
-
this.keepAlive = typeof (value = agent
|
|
644
|
-
this.acceptEncoding = typeof (value = use
|
|
645
|
-
if ((value = (0, util_1.asInt)(use
|
|
645
|
+
this.keepAlive = typeof (value = agent === null || agent === void 0 ? void 0 : agent.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
|
|
646
|
+
this.acceptEncoding = typeof (value = use === null || use === void 0 ? void 0 : use.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
|
|
647
|
+
if ((value = (0, util_1.asInt)(use === null || use === void 0 ? void 0 : use.http_version)) === 1 || value === 2) {
|
|
646
648
|
this[kHttpVersion] = value;
|
|
647
649
|
}
|
|
648
|
-
this[kIpVersion] = (value = (0, util_1.asInt)(data.dns
|
|
649
|
-
if ((value = (0, util_1.fromSeconds)(agent
|
|
650
|
+
this[kIpVersion] = (value = (0, util_1.asInt)((_l = data.dns) === null || _l === void 0 ? void 0 : _l.family)) && (value === 4 || value === 6) ? value : 0;
|
|
651
|
+
if ((value = (0, util_1.fromSeconds)(agent === null || agent === void 0 ? void 0 : agent.timeout)) >= 0) {
|
|
650
652
|
this[kAgentTimeout] = value;
|
|
651
653
|
}
|
|
652
654
|
else {
|
|
@@ -688,12 +690,13 @@ class Request extends module_1.default {
|
|
|
688
690
|
this.module = data;
|
|
689
691
|
}
|
|
690
692
|
flushLog() {
|
|
693
|
+
var _l;
|
|
691
694
|
const log = this._logQueued;
|
|
692
695
|
if (this[kSingleton]) {
|
|
693
696
|
log.length = 0;
|
|
694
697
|
}
|
|
695
698
|
else {
|
|
696
|
-
if (log.length && !this.host
|
|
699
|
+
if (log.length && !((_l = this.host) === null || _l === void 0 ? void 0 : _l.aborted)) {
|
|
697
700
|
const output = [];
|
|
698
701
|
let count = 0;
|
|
699
702
|
this[kConnectHttp].forEach((protocol, index) => {
|
|
@@ -1016,8 +1019,9 @@ class Request extends module_1.default {
|
|
|
1016
1019
|
if (!module_1.default.createDir(pathname)) {
|
|
1017
1020
|
return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
|
|
1018
1021
|
}
|
|
1019
|
-
silent
|
|
1022
|
+
silent !== null && silent !== void 0 ? silent : (silent = this[kSingleton]);
|
|
1020
1023
|
return new Promise((resolve, reject) => {
|
|
1024
|
+
var _l;
|
|
1021
1025
|
let protocol, origin, username, password;
|
|
1022
1026
|
if (uri instanceof URL) {
|
|
1023
1027
|
({ protocol, origin, username, password, href: uri } = uri);
|
|
@@ -1075,7 +1079,7 @@ class Request extends module_1.default {
|
|
|
1075
1079
|
'--file-allocation=' + ARIA2.FILE_ALLOCATION,
|
|
1076
1080
|
'--max-tries=' + (retryLimit + 1)
|
|
1077
1081
|
];
|
|
1078
|
-
const ignoreOpt = (...values) => !binOpts
|
|
1082
|
+
const ignoreOpt = (...values) => !(binOpts === null || binOpts === void 0 ? void 0 : binOpts.some(item => values.includes(item)));
|
|
1079
1083
|
if (ARIA2.MAX_CONCURRENT_DOWNLOADS) {
|
|
1080
1084
|
opts.push('--max-concurrent-downloads=' + ARIA2.MAX_CONCURRENT_DOWNLOADS);
|
|
1081
1085
|
}
|
|
@@ -1124,7 +1128,7 @@ class Request extends module_1.default {
|
|
|
1124
1128
|
}
|
|
1125
1129
|
}
|
|
1126
1130
|
if (origin) {
|
|
1127
|
-
const secure = this[kCerts]
|
|
1131
|
+
const secure = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[1][origin]) || (this.host ? TLS.FILE[origin] : null);
|
|
1128
1132
|
if (secure) {
|
|
1129
1133
|
if (secure.ca && ignoreOpt('--ca-certificate')) {
|
|
1130
1134
|
args.push(`--ca-certificate="${escapeQuote(secure.ca)}"`);
|
|
@@ -1274,7 +1278,7 @@ class Request extends module_1.default {
|
|
|
1274
1278
|
}
|
|
1275
1279
|
else {
|
|
1276
1280
|
const current = (0, types_1.getLogCurrent)();
|
|
1277
|
-
progressBar = current
|
|
1281
|
+
progressBar = (current === null || current === void 0 ? void 0 : current.type) === 128 && current.title === "aria2";
|
|
1278
1282
|
}
|
|
1279
1283
|
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 });
|
|
1280
1284
|
}
|
|
@@ -1313,7 +1317,8 @@ class Request extends module_1.default {
|
|
|
1313
1317
|
return { ...options, host, url };
|
|
1314
1318
|
}
|
|
1315
1319
|
open(uri, options) {
|
|
1316
|
-
var _l
|
|
1320
|
+
var _l;
|
|
1321
|
+
var _m, _o;
|
|
1317
1322
|
let { host, url, httpVersion, method = 'GET', encoding, format, headers, postData, keepAlive, agentTimeout, socketPath, timeout = this._config.connectTimeout, outStream } = options;
|
|
1318
1323
|
const getting = method === 'GET';
|
|
1319
1324
|
const posting = method === 'POST';
|
|
@@ -1368,7 +1373,7 @@ class Request extends module_1.default {
|
|
|
1368
1373
|
case 204:
|
|
1369
1374
|
return;
|
|
1370
1375
|
}
|
|
1371
|
-
const chunkSize = outStream
|
|
1376
|
+
const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
|
|
1372
1377
|
let pipeTo;
|
|
1373
1378
|
switch (contentEncoding.trim().toLowerCase()) {
|
|
1374
1379
|
case 'gzip':
|
|
@@ -1404,17 +1409,17 @@ class Request extends module_1.default {
|
|
|
1404
1409
|
const proxy = this.proxyOf(uri, localhost);
|
|
1405
1410
|
const version = this.httpVersion;
|
|
1406
1411
|
let request, ca, cert, key, minVersion, baseHeaders = this.headersOf(uri);
|
|
1407
|
-
if (getting && this.acceptEncoding && !localhost && !baseHeaders
|
|
1408
|
-
(
|
|
1412
|
+
if (getting && this.acceptEncoding && !localhost && !(baseHeaders === null || baseHeaders === void 0 ? void 0 : baseHeaders['accept-encoding'])) {
|
|
1413
|
+
(_m = (headers || (headers = {})))['accept-encoding'] || (_m['accept-encoding'] = 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : ''));
|
|
1409
1414
|
}
|
|
1410
1415
|
if (secure) {
|
|
1411
|
-
const certs = this[kCerts]
|
|
1416
|
+
const certs = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[0][origin]) || (this.host ? TLS.TEXT[origin] : null);
|
|
1412
1417
|
if (certs) {
|
|
1413
1418
|
({ ca, cert, key, version: minVersion } = certs);
|
|
1414
1419
|
}
|
|
1415
1420
|
}
|
|
1416
1421
|
if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
|
|
1417
|
-
request = ((
|
|
1422
|
+
request = ((_o = this[kSession][0])[origin] || (_o[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 });
|
|
1418
1423
|
if (getting) {
|
|
1419
1424
|
const listenerMap = {};
|
|
1420
1425
|
const onEvent = request.on.bind(request);
|
|
@@ -1497,8 +1502,8 @@ class Request extends module_1.default {
|
|
|
1497
1502
|
const pkg = secure ? 'https-proxy-agent' : 'http-proxy-agent';
|
|
1498
1503
|
try {
|
|
1499
1504
|
const { protocol, hostname: proxyname, port, username, password, href } = proxy.host;
|
|
1500
|
-
keepAlive
|
|
1501
|
-
agentTimeout
|
|
1505
|
+
keepAlive !== null && keepAlive !== void 0 ? keepAlive : (keepAlive = proxy.keepAlive || false);
|
|
1506
|
+
agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = proxy.agentTimeout);
|
|
1502
1507
|
agent = require(pkg)(keepAlive || agentTimeout > 0 ? { protocol, hostname: proxyname, port, username, password, keepAlive, timeout: agentTimeout } : href);
|
|
1503
1508
|
const proxyHeaders = this[kHeaders] && getBaseHeaders(href, this[kHeaders]) || getBaseHeaders(href, HTTP.HEADERS);
|
|
1504
1509
|
if (proxyHeaders) {
|
|
@@ -1517,7 +1522,7 @@ class Request extends module_1.default {
|
|
|
1517
1522
|
}
|
|
1518
1523
|
else if (agentTimeout !== 0) {
|
|
1519
1524
|
keepAlive = this.keepAlive || false;
|
|
1520
|
-
agentTimeout
|
|
1525
|
+
agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = this.agentTimeout);
|
|
1521
1526
|
if (keepAlive || agentTimeout > 0) {
|
|
1522
1527
|
agent = new (secure ? https.Agent : http.Agent)({ keepAlive, timeout: agentTimeout });
|
|
1523
1528
|
}
|
|
@@ -1541,6 +1546,7 @@ class Request extends module_1.default {
|
|
|
1541
1546
|
lookup: this.lookupDns(hostname),
|
|
1542
1547
|
agent
|
|
1543
1548
|
}, response => {
|
|
1549
|
+
var _l;
|
|
1544
1550
|
const statusCode = response.statusCode;
|
|
1545
1551
|
if ((getting || posting) && statusCode >= 200 && statusCode < 300) {
|
|
1546
1552
|
const incoming = response.headers;
|
|
@@ -1576,7 +1582,7 @@ class Request extends module_1.default {
|
|
|
1576
1582
|
source.on('error', err => request.emit('error', err));
|
|
1577
1583
|
}
|
|
1578
1584
|
if (!posting) {
|
|
1579
|
-
if (version === 2 && incoming.upgrade
|
|
1585
|
+
if (version === 2 && ((_l = incoming.upgrade) === null || _l === void 0 ? void 0 : _l.includes('h2'))) {
|
|
1580
1586
|
host.version = 2;
|
|
1581
1587
|
}
|
|
1582
1588
|
else if (!host.didAltSvc(1)) {
|
|
@@ -1774,7 +1780,7 @@ class Request extends module_1.default {
|
|
|
1774
1780
|
async get(uri, options = {}) {
|
|
1775
1781
|
const opts = (typeof options === 'string' ? { format: options, encoding: 'utf-8' } : options);
|
|
1776
1782
|
if (this.readExpect === 'string') {
|
|
1777
|
-
opts.encoding = (0, types_1.getEncoding)(opts
|
|
1783
|
+
opts.encoding = (0, types_1.getEncoding)(opts === null || opts === void 0 ? void 0 : opts.encoding);
|
|
1778
1784
|
}
|
|
1779
1785
|
return new Promise((resolve, reject) => {
|
|
1780
1786
|
const { silent = this[kSingleton], pipeTo } = opts;
|
|
@@ -1848,19 +1854,21 @@ class Request extends module_1.default {
|
|
|
1848
1854
|
downloadUri.call(this, href);
|
|
1849
1855
|
};
|
|
1850
1856
|
const acceptResponse = (headers) => {
|
|
1857
|
+
var _l;
|
|
1851
1858
|
if ('outHeaders' in opts) {
|
|
1852
1859
|
opts.outHeaders = headers;
|
|
1853
1860
|
}
|
|
1854
1861
|
if ('outFilename' in opts) {
|
|
1855
1862
|
opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
|
|
1856
1863
|
}
|
|
1857
|
-
const buffering = request.connected
|
|
1864
|
+
const buffering = (_l = request.connected) === null || _l === void 0 ? void 0 : _l.call(client, headers);
|
|
1858
1865
|
const pipeline = pipeTo ? !(0, types_1.isString)(pipeTo) : false;
|
|
1859
1866
|
const enabled = buffering !== false && !pipeline;
|
|
1860
1867
|
const readTimeout = this.readTimeout;
|
|
1861
1868
|
let mibsTime, delayTime;
|
|
1862
1869
|
if (log || readTimeout > 0) {
|
|
1863
1870
|
client.once('readable', () => {
|
|
1871
|
+
var _l;
|
|
1864
1872
|
if (readTimeout > 0) {
|
|
1865
1873
|
timeout = setTimeout(() => {
|
|
1866
1874
|
abortResponse();
|
|
@@ -1871,7 +1879,7 @@ class Request extends module_1.default {
|
|
|
1871
1879
|
if (buffering === false) {
|
|
1872
1880
|
mibsTime = process.hrtime();
|
|
1873
1881
|
}
|
|
1874
|
-
switch (this.settings
|
|
1882
|
+
switch (((_l = this.settings) === null || _l === void 0 ? void 0 : _l.time_format) || LOG_TIMEFORMAT) {
|
|
1875
1883
|
case 'readable':
|
|
1876
1884
|
delayTime = process.hrtime(startTime);
|
|
1877
1885
|
break;
|
|
@@ -2198,13 +2206,14 @@ class Request extends module_1.default {
|
|
|
2198
2206
|
this[kDownloading].clear();
|
|
2199
2207
|
}
|
|
2200
2208
|
set agentTimeout(value) {
|
|
2209
|
+
var _l, _m;
|
|
2201
2210
|
if (value > 0) {
|
|
2202
2211
|
this[kAgentTimeout] = value;
|
|
2203
|
-
this.keepAlive
|
|
2212
|
+
(_l = this.keepAlive) !== null && _l !== void 0 ? _l : (this.keepAlive = true);
|
|
2204
2213
|
}
|
|
2205
2214
|
else {
|
|
2206
2215
|
this[kAgentTimeout] = 0;
|
|
2207
|
-
this.keepAlive
|
|
2216
|
+
(_m = this.keepAlive) !== null && _m !== void 0 ? _m : (this.keepAlive = false);
|
|
2208
2217
|
}
|
|
2209
2218
|
}
|
|
2210
2219
|
get agentTimeout() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
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.5",
|
|
24
|
+
"@e-mc/types": "0.7.5",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"which": "^2.0.2"
|