@e-mc/request 0.8.10 → 0.8.11
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 +61 -43
- package/package.json +3 -3
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.11/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.11/lib/http.d.ts
|
|
86
|
+
- https://www.unpkg.com/@e-mc/types@0.8.11/lib/request.d.ts
|
|
87
|
+
- https://www.unpkg.com/@e-mc/types@0.8.11/lib/settings.d.ts
|
|
88
88
|
|
|
89
89
|
## LICENSE
|
|
90
90
|
|
package/index.js
CHANGED
|
@@ -261,6 +261,61 @@ function validateCerts(certs) {
|
|
|
261
261
|
}
|
|
262
262
|
return [text, file];
|
|
263
263
|
}
|
|
264
|
+
function checkEncoding(request, response, statusCode, outStream, contentEncoding = '') {
|
|
265
|
+
switch (statusCode) {
|
|
266
|
+
case 206:
|
|
267
|
+
request.emit('error', (0, types_1.errorValue)("Aborted", 'Partial content'));
|
|
268
|
+
case 204:
|
|
269
|
+
return;
|
|
270
|
+
default:
|
|
271
|
+
contentEncoding = contentEncoding.trim();
|
|
272
|
+
if (!contentEncoding) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
contentEncoding = contentEncoding.toLowerCase();
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
|
|
279
|
+
let pipeTo;
|
|
280
|
+
if (contentEncoding.indexOf(',') === -1) {
|
|
281
|
+
pipeTo = decompressEncoding(contentEncoding, chunkSize);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
for (const value of contentEncoding.split(/\s*,\s*/).reverse()) {
|
|
285
|
+
const next = decompressEncoding(value, chunkSize);
|
|
286
|
+
if (!next) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
pipeTo = pipeTo ? pipeTo.pipe(next) : next;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (pipeTo) {
|
|
293
|
+
if (outStream) {
|
|
294
|
+
stream.pipeline(response, pipeTo, outStream, err => err && response.emit('error', err));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
stream.pipeline(response, pipeTo, err => err && response.emit('error', err));
|
|
298
|
+
}
|
|
299
|
+
return pipeTo;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function decompressEncoding(value, chunkSize) {
|
|
303
|
+
switch (value) {
|
|
304
|
+
case 'gzip':
|
|
305
|
+
return zlib.createGunzip({ chunkSize });
|
|
306
|
+
case 'br':
|
|
307
|
+
return zlib.createBrotliDecompress({ chunkSize });
|
|
308
|
+
case 'deflate':
|
|
309
|
+
return zlib.createInflate({ chunkSize });
|
|
310
|
+
case 'deflate-raw':
|
|
311
|
+
return zlib.createInflateRaw({ chunkSize });
|
|
312
|
+
case 'zstd':
|
|
313
|
+
if (LIB_ZSTD) {
|
|
314
|
+
return new LIB_ZSTD.ZstdDecompressTransform({ writableHighWaterMark: chunkSize });
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
264
319
|
function abortHeaders(href, request, options) {
|
|
265
320
|
const reason = (0, types_1.errorValue)("Aborted by client", href);
|
|
266
321
|
const outAbort = options.outAbort;
|
|
@@ -1421,44 +1476,6 @@ class Request extends module_1.default {
|
|
|
1421
1476
|
url = new URL(uri);
|
|
1422
1477
|
options.url = url;
|
|
1423
1478
|
}
|
|
1424
|
-
const checkEncoding = (response, statusCode, contentEncoding = '') => {
|
|
1425
|
-
switch (statusCode) {
|
|
1426
|
-
case 206:
|
|
1427
|
-
request.emit('error', (0, types_1.errorValue)("Aborted", 'Partial content'));
|
|
1428
|
-
case 204:
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
|
|
1432
|
-
let pipeTo;
|
|
1433
|
-
switch (contentEncoding.trim().toLowerCase()) {
|
|
1434
|
-
case 'gzip':
|
|
1435
|
-
pipeTo = zlib.createGunzip({ chunkSize });
|
|
1436
|
-
break;
|
|
1437
|
-
case 'br':
|
|
1438
|
-
pipeTo = zlib.createBrotliDecompress({ chunkSize });
|
|
1439
|
-
break;
|
|
1440
|
-
case 'deflate':
|
|
1441
|
-
pipeTo = zlib.createInflate({ chunkSize });
|
|
1442
|
-
break;
|
|
1443
|
-
case 'deflate-raw':
|
|
1444
|
-
pipeTo = zlib.createInflateRaw({ chunkSize });
|
|
1445
|
-
break;
|
|
1446
|
-
case 'zstd':
|
|
1447
|
-
if (LIB_ZSTD) {
|
|
1448
|
-
pipeTo = new LIB_ZSTD.ZstdDecompressTransform({ writableHighWaterMark: chunkSize });
|
|
1449
|
-
}
|
|
1450
|
-
break;
|
|
1451
|
-
}
|
|
1452
|
-
if (pipeTo) {
|
|
1453
|
-
if (outStream) {
|
|
1454
|
-
stream.pipeline(response, pipeTo, outStream, err => err && response.emit('error', err));
|
|
1455
|
-
}
|
|
1456
|
-
else {
|
|
1457
|
-
stream.pipeline(response, pipeTo, err => err && response.emit('error', err));
|
|
1458
|
-
}
|
|
1459
|
-
return pipeTo;
|
|
1460
|
-
}
|
|
1461
|
-
};
|
|
1462
1479
|
const { hostname, origin, secure, localhost } = host;
|
|
1463
1480
|
const pathname = url.pathname + (socketPath ? '' : url.search);
|
|
1464
1481
|
const proxy = this.proxyOf(uri, localhost);
|
|
@@ -1484,7 +1501,8 @@ class Request extends module_1.default {
|
|
|
1484
1501
|
connected = true;
|
|
1485
1502
|
const statusCode = response[':status'];
|
|
1486
1503
|
if (this.matchStatus(statusCode, url, response, request, options) && statusCode >= 200 && statusCode < 300) {
|
|
1487
|
-
|
|
1504
|
+
emitter = checkEncoding(request, request, statusCode, outStream, response['content-encoding']);
|
|
1505
|
+
if (emitter) {
|
|
1488
1506
|
for (const event in listenerMap) {
|
|
1489
1507
|
listenerMap[event].forEach(listener => {
|
|
1490
1508
|
const [name, type] = event.split('-');
|
|
@@ -1606,7 +1624,7 @@ class Request extends module_1.default {
|
|
|
1606
1624
|
const statusCode = response.statusCode;
|
|
1607
1625
|
const incoming = response.headers;
|
|
1608
1626
|
if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200 && statusCode < 300) {
|
|
1609
|
-
let source = checkEncoding(response, statusCode, incoming['content-encoding']);
|
|
1627
|
+
let source = checkEncoding(request, response, statusCode, outStream, incoming['content-encoding']);
|
|
1610
1628
|
if (source) {
|
|
1611
1629
|
source.once('finish', () => request.emit('end'));
|
|
1612
1630
|
}
|
|
@@ -1845,6 +1863,9 @@ class Request extends module_1.default {
|
|
|
1845
1863
|
const startTime = log ? process.hrtime() : 0;
|
|
1846
1864
|
let retries = 0, redirects = 0, closed, timeout, outStream;
|
|
1847
1865
|
const throwError = (err, outAbort) => {
|
|
1866
|
+
if (timeout) {
|
|
1867
|
+
clearTimeout(timeout);
|
|
1868
|
+
}
|
|
1848
1869
|
if (!closed) {
|
|
1849
1870
|
closed = true;
|
|
1850
1871
|
if (outStream && (0, types_1.isString)(pipeTo)) {
|
|
@@ -1852,9 +1873,6 @@ class Request extends module_1.default {
|
|
|
1852
1873
|
}
|
|
1853
1874
|
reject(typeof err === 'string' ? new Error(err) : err);
|
|
1854
1875
|
}
|
|
1855
|
-
if (timeout) {
|
|
1856
|
-
clearTimeout(timeout);
|
|
1857
|
-
}
|
|
1858
1876
|
if (outAbort) {
|
|
1859
1877
|
this[kDownloading].delete(outAbort);
|
|
1860
1878
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
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.11",
|
|
24
|
+
"@e-mc/types": "0.8.11",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^3.0.1",
|