@e-mc/request 0.9.1 → 0.9.2
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 +4 -4
- package/index.js +39 -29
- package/package.json +3 -3
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.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.2/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -201,9 +201,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
201
201
|
|
|
202
202
|
## References
|
|
203
203
|
|
|
204
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
205
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
206
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
204
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/http.d.ts
|
|
205
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/request.d.ts
|
|
206
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/settings.d.ts
|
|
207
207
|
|
|
208
208
|
* https://www.npmjs.com/package/@types/node
|
|
209
209
|
|
package/index.js
CHANGED
|
@@ -877,7 +877,12 @@ class Request extends module_1 {
|
|
|
877
877
|
const resolved = this[kConnectDns][hostname] || DNS.CACHE[hostname];
|
|
878
878
|
if (resolved) {
|
|
879
879
|
return (...args) => {
|
|
880
|
-
|
|
880
|
+
if (SUPPORT_NODEJS20) {
|
|
881
|
+
args[2](null, resolved);
|
|
882
|
+
}
|
|
883
|
+
else {
|
|
884
|
+
args[2](null, resolved[0].address, resolved[0].family);
|
|
885
|
+
}
|
|
881
886
|
};
|
|
882
887
|
}
|
|
883
888
|
const pending = (_o = this[kPendingDns])[hostname] || (_o[hostname] = []);
|
|
@@ -1832,11 +1837,14 @@ class Request extends module_1 {
|
|
|
1832
1837
|
opts.encoding = (0, types_1.getEncoding)(opts.encoding);
|
|
1833
1838
|
}
|
|
1834
1839
|
return new Promise((resolve, reject) => {
|
|
1835
|
-
const
|
|
1836
|
-
const
|
|
1840
|
+
const pipeTo = opts.pipeTo;
|
|
1841
|
+
const status = opts.silent === false || !opts.silent && !this[kSingleton];
|
|
1842
|
+
let log = status && LOG_HTTP && LOG_TIMEPROCESS, retries = 0, redirects = 0, closed, timeout, outStream;
|
|
1837
1843
|
const startTime = log ? process.hrtime() : 0;
|
|
1838
|
-
let retries = 0, redirects = 0, closed, timeout, outStream;
|
|
1839
1844
|
const throwError = (err, outAbort) => {
|
|
1845
|
+
if (timeout) {
|
|
1846
|
+
clearTimeout(timeout);
|
|
1847
|
+
}
|
|
1840
1848
|
if (!closed) {
|
|
1841
1849
|
closed = true;
|
|
1842
1850
|
if (outStream && (0, types_1.isString)(pipeTo)) {
|
|
@@ -1844,9 +1852,6 @@ class Request extends module_1 {
|
|
|
1844
1852
|
}
|
|
1845
1853
|
reject(typeof err === 'string' ? new Error(err) : err);
|
|
1846
1854
|
}
|
|
1847
|
-
if (timeout) {
|
|
1848
|
-
clearTimeout(timeout);
|
|
1849
|
-
}
|
|
1850
1855
|
if (outAbort) {
|
|
1851
1856
|
this[kDownloading].delete(outAbort);
|
|
1852
1857
|
}
|
|
@@ -1880,7 +1885,8 @@ class Request extends module_1 {
|
|
|
1880
1885
|
const isUnsupported = (value) => value === 421 || value === 505;
|
|
1881
1886
|
const isDowngrade = (err) => err instanceof Error && (err.code === 'ERR_HTTP2_ERROR' || isUnsupported(Math.abs(err.errno)));
|
|
1882
1887
|
const wasAborted = (err) => err instanceof Error && err.message.startsWith("Aborted");
|
|
1883
|
-
const
|
|
1888
|
+
const sendWarning = (message) => status && LOG_HTTP && this.formatMessage(1024, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { ...module_1.LOG_STYLE_WARN });
|
|
1889
|
+
const formatRetry = (message) => message + ` (${retries} / ${this._config.retryLimit})`;
|
|
1884
1890
|
const formatNgFlags = (value, statusCode, location) => location ? `Using HTTP 1.1 for URL redirect (${location})` : formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
|
|
1885
1891
|
const abortResponse = () => {
|
|
1886
1892
|
if (closed) {
|
|
@@ -1900,7 +1906,7 @@ class Request extends module_1 {
|
|
|
1900
1906
|
client.destroy();
|
|
1901
1907
|
};
|
|
1902
1908
|
const retryTimeout = () => {
|
|
1903
|
-
|
|
1909
|
+
sendWarning(formatRetry('Connection timeout'));
|
|
1904
1910
|
downloadUri.call(this, href);
|
|
1905
1911
|
};
|
|
1906
1912
|
const acceptResponse = (headers) => {
|
|
@@ -1910,9 +1916,8 @@ class Request extends module_1 {
|
|
|
1910
1916
|
if ('outFilename' in opts) {
|
|
1911
1917
|
opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
|
|
1912
1918
|
}
|
|
1913
|
-
const buffering = request.connected?.call(client, headers);
|
|
1914
1919
|
const pipeline = pipeTo ? !(0, types_1.isString)(pipeTo) : false;
|
|
1915
|
-
const enabled =
|
|
1920
|
+
const enabled = request.connected?.call(client, headers) !== false && !pipeline;
|
|
1916
1921
|
const maxBufferSize = request.maxBufferSize ? (0, types_1.alignSize)(request.maxBufferSize) : 0;
|
|
1917
1922
|
const { host: parent, readTimeout } = this;
|
|
1918
1923
|
const contentLength = parent && progressId !== undefined ? parseInt(headers['content-length'] || '0') : 0;
|
|
@@ -1926,13 +1931,18 @@ class Request extends module_1 {
|
|
|
1926
1931
|
}, readTimeout);
|
|
1927
1932
|
}
|
|
1928
1933
|
if (log) {
|
|
1929
|
-
switch (this.settings
|
|
1934
|
+
switch (this.settings.time_format || LOG_TIMEFORMAT) {
|
|
1930
1935
|
case 'readable':
|
|
1931
1936
|
delayTime = process.hrtime(startTime);
|
|
1932
1937
|
break;
|
|
1933
1938
|
case 'relative':
|
|
1934
1939
|
delayTime = Date.now() - this.startTime;
|
|
1935
1940
|
break;
|
|
1941
|
+
case 'none':
|
|
1942
|
+
if (opts.silent !== false) {
|
|
1943
|
+
log = false;
|
|
1944
|
+
}
|
|
1945
|
+
break;
|
|
1936
1946
|
}
|
|
1937
1947
|
}
|
|
1938
1948
|
mibsTime = process.hrtime();
|
|
@@ -1983,8 +1993,7 @@ class Request extends module_1 {
|
|
|
1983
1993
|
this[kDownloading].delete(outAbort);
|
|
1984
1994
|
}
|
|
1985
1995
|
closed = true;
|
|
1986
|
-
let messageUnit, titleBgColor;
|
|
1987
|
-
let result;
|
|
1996
|
+
let result, messageUnit, titleBgColor;
|
|
1988
1997
|
if (buffer) {
|
|
1989
1998
|
if (Array.isArray(buffer)) {
|
|
1990
1999
|
buffer = Buffer.concat(buffer);
|
|
@@ -2029,7 +2038,7 @@ class Request extends module_1 {
|
|
|
2029
2038
|
}
|
|
2030
2039
|
}
|
|
2031
2040
|
catch (err) {
|
|
2032
|
-
if (
|
|
2041
|
+
if (status && !(packageName && this.checkPackage(err, packageName))) {
|
|
2033
2042
|
this.writeFail(['Unable to parse URI response', format], err, 1024);
|
|
2034
2043
|
}
|
|
2035
2044
|
result = null;
|
|
@@ -2105,7 +2114,7 @@ class Request extends module_1 {
|
|
|
2105
2114
|
}
|
|
2106
2115
|
if (offset > 0) {
|
|
2107
2116
|
if (offset <= this._config.retryAfter) {
|
|
2108
|
-
|
|
2117
|
+
sendWarning(`Retry After (${retryAfter})`);
|
|
2109
2118
|
setTimeout(() => downloadUri.call(this, href), offset);
|
|
2110
2119
|
}
|
|
2111
2120
|
else {
|
|
@@ -2114,7 +2123,7 @@ class Request extends module_1 {
|
|
|
2114
2123
|
return;
|
|
2115
2124
|
}
|
|
2116
2125
|
}
|
|
2117
|
-
|
|
2126
|
+
sendWarning(formatRetry(Request.fromStatusCode(statusCode)));
|
|
2118
2127
|
if ((0, util_1.isRetryable)(statusCode, true)) {
|
|
2119
2128
|
process.nextTick(downloadUri.bind(this), href);
|
|
2120
2129
|
}
|
|
@@ -2131,7 +2140,7 @@ class Request extends module_1 {
|
|
|
2131
2140
|
if (downgrade) {
|
|
2132
2141
|
host.failed(2);
|
|
2133
2142
|
if (host.version > 1) {
|
|
2134
|
-
if (
|
|
2143
|
+
if (status && LOG_HTTP) {
|
|
2135
2144
|
this.formatMessage(1024, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
|
|
2136
2145
|
}
|
|
2137
2146
|
host.version = 1;
|
|
@@ -2193,18 +2202,19 @@ class Request extends module_1 {
|
|
|
2193
2202
|
}
|
|
2194
2203
|
if (wasAborted(err)) {
|
|
2195
2204
|
errorResponse(err);
|
|
2196
|
-
return;
|
|
2197
2205
|
}
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2206
|
+
else {
|
|
2207
|
+
switch (!isDowngrade(err) && await host.hasProtocol(2)) {
|
|
2208
|
+
case 1:
|
|
2209
|
+
errorResponse(err);
|
|
2210
|
+
break;
|
|
2211
|
+
case 2:
|
|
2212
|
+
retryDownload(false, err);
|
|
2213
|
+
break;
|
|
2214
|
+
default:
|
|
2215
|
+
retryDownload(true, err);
|
|
2216
|
+
break;
|
|
2217
|
+
}
|
|
2208
2218
|
}
|
|
2209
2219
|
});
|
|
2210
2220
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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.
|
|
24
|
-
"@e-mc/types": "0.9.
|
|
23
|
+
"@e-mc/module": "0.9.2",
|
|
24
|
+
"@e-mc/types": "0.9.2",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^4.0.2",
|