@e-mc/request 0.8.20 → 0.8.21
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/README.md +4 -4
- package/index.js +19 -18
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2023 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/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.21/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -82,9 +82,9 @@ interface RequestConstructor extends ModuleConstructor {
|
|
|
82
82
|
|
|
83
83
|
## References
|
|
84
84
|
|
|
85
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
86
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
87
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
85
|
+
- https://www.unpkg.com/@e-mc/types@0.8.21/lib/http.d.ts
|
|
86
|
+
- https://www.unpkg.com/@e-mc/types@0.8.21/lib/request.d.ts
|
|
87
|
+
- https://www.unpkg.com/@e-mc/types@0.8.21/lib/settings.d.ts
|
|
88
88
|
|
|
89
89
|
## LICENSE
|
|
90
90
|
|
package/index.js
CHANGED
|
@@ -316,8 +316,8 @@ function decompressEncoding(value, chunkSize) {
|
|
|
316
316
|
break;
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
|
-
function abortHeaders(href, request, options) {
|
|
320
|
-
const reason = (0, types_1.
|
|
319
|
+
function abortHeaders(href, request, options, statusCode = '') {
|
|
320
|
+
const reason = (0, types_1.errorMessage)(statusCode, "Aborted by client", href);
|
|
321
321
|
const outAbort = options.outAbort;
|
|
322
322
|
if (outAbort) {
|
|
323
323
|
outAbort.abort(reason);
|
|
@@ -1061,13 +1061,13 @@ class Request extends module_1.default {
|
|
|
1061
1061
|
return Promise.reject(err);
|
|
1062
1062
|
}
|
|
1063
1063
|
}
|
|
1064
|
-
let pathname, headers, binOpts, silent;
|
|
1064
|
+
let pathname, headers, binOpts, signal, silent;
|
|
1065
1065
|
if (options) {
|
|
1066
1066
|
if (typeof options === 'string') {
|
|
1067
1067
|
pathname = options;
|
|
1068
1068
|
}
|
|
1069
1069
|
else {
|
|
1070
|
-
({ pathname, headers, binOpts, silent } = options);
|
|
1070
|
+
({ pathname, headers, binOpts, signal, silent } = options);
|
|
1071
1071
|
if ((0, types_1.isArray)(binOpts)) {
|
|
1072
1072
|
let next = false;
|
|
1073
1073
|
binOpts = binOpts.filter(opt => !((0, types_1.isString)(opt) && /^-[a-z][\S\s]*$/i.test(opt.trim()))).map((opt) => {
|
|
@@ -1371,7 +1371,13 @@ class Request extends module_1.default {
|
|
|
1371
1371
|
}
|
|
1372
1372
|
for (const item of ARIA2.PID_QUEUE) {
|
|
1373
1373
|
try {
|
|
1374
|
-
|
|
1374
|
+
if (pid === item[0] && (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
|
|
1375
|
+
process.kill(item[0]);
|
|
1376
|
+
closeTorrent(item[0]);
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
process.kill(item[0], 0);
|
|
1380
|
+
}
|
|
1375
1381
|
}
|
|
1376
1382
|
catch {
|
|
1377
1383
|
closeTorrent(item[0]);
|
|
@@ -1686,6 +1692,9 @@ class Request extends module_1.default {
|
|
|
1686
1692
|
const ac = new AbortController();
|
|
1687
1693
|
this[kDownloading].add(options.outAbort = ac);
|
|
1688
1694
|
stream.addAbortSignal(ac.signal, request);
|
|
1695
|
+
if (options.signal) {
|
|
1696
|
+
stream.addAbortSignal(options.signal, request);
|
|
1697
|
+
}
|
|
1689
1698
|
this.signal.addEventListener('abort', () => ac.abort(new Error("Aborted by process")), { once: true });
|
|
1690
1699
|
}
|
|
1691
1700
|
if (posting) {
|
|
@@ -1898,7 +1907,7 @@ class Request extends module_1.default {
|
|
|
1898
1907
|
}
|
|
1899
1908
|
const client = this.open(href, request);
|
|
1900
1909
|
const { host, url, encoding, outFormat } = request;
|
|
1901
|
-
let buffer, aborted;
|
|
1910
|
+
let buffer, aborted = false;
|
|
1902
1911
|
({ httpVersion, outAbort } = request);
|
|
1903
1912
|
const isAborted = () => client.destroyed || httpVersion === 2 && client.aborted;
|
|
1904
1913
|
const isRetry = (value) => (0, util_1.isRetryable)(value) && ++retries <= this._config.retryLimit;
|
|
@@ -1916,12 +1925,6 @@ class Request extends module_1.default {
|
|
|
1916
1925
|
}
|
|
1917
1926
|
buffer = null;
|
|
1918
1927
|
aborted = true;
|
|
1919
|
-
if (outAbort) {
|
|
1920
|
-
if (!client.aborted) {
|
|
1921
|
-
outAbort.abort();
|
|
1922
|
-
}
|
|
1923
|
-
this[kDownloading].delete(outAbort);
|
|
1924
|
-
}
|
|
1925
1928
|
client.destroy();
|
|
1926
1929
|
};
|
|
1927
1930
|
const retryTimeout = () => {
|
|
@@ -1946,7 +1949,6 @@ class Request extends module_1.default {
|
|
|
1946
1949
|
var _o;
|
|
1947
1950
|
if (readTimeout > 0) {
|
|
1948
1951
|
timeout = setTimeout(() => {
|
|
1949
|
-
abortResponse();
|
|
1950
1952
|
throwError((0, types_1.errorValue)("Timeout was exceeded", href.toString()));
|
|
1951
1953
|
}, readTimeout);
|
|
1952
1954
|
}
|
|
@@ -2070,9 +2072,9 @@ class Request extends module_1.default {
|
|
|
2070
2072
|
host.success(httpVersion);
|
|
2071
2073
|
};
|
|
2072
2074
|
const redirectResponse = (statusCode, location) => {
|
|
2073
|
-
abortResponse();
|
|
2074
2075
|
if (location) {
|
|
2075
2076
|
if (++redirects <= this._config.redirectLimit) {
|
|
2077
|
+
abortResponse();
|
|
2076
2078
|
downloadUri.call(this, Request.fromURL(url, location));
|
|
2077
2079
|
}
|
|
2078
2080
|
else {
|
|
@@ -2084,11 +2086,11 @@ class Request extends module_1.default {
|
|
|
2084
2086
|
}
|
|
2085
2087
|
};
|
|
2086
2088
|
const errorResponse = (err) => {
|
|
2087
|
-
abortResponse();
|
|
2088
2089
|
if (wasAborted(err)) {
|
|
2089
2090
|
throwError(err);
|
|
2090
2091
|
}
|
|
2091
2092
|
else if ((0, util_1.checkRetryable)(err) && ++retries <= this._config.retryLimit) {
|
|
2093
|
+
abortResponse();
|
|
2092
2094
|
if (isConnectionTimeout(err)) {
|
|
2093
2095
|
retryTimeout();
|
|
2094
2096
|
}
|
|
@@ -2233,7 +2235,6 @@ class Request extends module_1.default {
|
|
|
2233
2235
|
retryResponse(statusCode, res.headers['retry-after']);
|
|
2234
2236
|
}
|
|
2235
2237
|
else {
|
|
2236
|
-
abortResponse();
|
|
2237
2238
|
throwError(formatStatus(statusCode));
|
|
2238
2239
|
}
|
|
2239
2240
|
})
|
|
@@ -2251,8 +2252,8 @@ class Request extends module_1.default {
|
|
|
2251
2252
|
if (aborted) {
|
|
2252
2253
|
return;
|
|
2253
2254
|
}
|
|
2254
|
-
abortResponse();
|
|
2255
2255
|
if (++retries <= this._config.retryLimit) {
|
|
2256
|
+
abortResponse();
|
|
2256
2257
|
retryTimeout();
|
|
2257
2258
|
}
|
|
2258
2259
|
else {
|
|
@@ -2294,7 +2295,7 @@ class Request extends module_1.default {
|
|
|
2294
2295
|
for (const callback of called) {
|
|
2295
2296
|
try {
|
|
2296
2297
|
if (callback(code, headers, url) === true) {
|
|
2297
|
-
abortHeaders.call(this, href, request, options);
|
|
2298
|
+
abortHeaders.call(this, href, request, options, code);
|
|
2298
2299
|
return false;
|
|
2299
2300
|
}
|
|
2300
2301
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.21",
|
|
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.8.
|
|
24
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/module": "0.8.21",
|
|
24
|
+
"@e-mc/types": "0.8.21",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^3.0.1",
|