@e-mc/request 0.11.3 → 0.11.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/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.11.3/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.5/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -209,9 +209,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
209
209
 
210
210
  ## References
211
211
 
212
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/http.d.ts
213
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/request.d.ts
214
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/settings.d.ts
212
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/http.d.ts
213
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/request.d.ts
214
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/settings.d.ts
215
215
 
216
216
  * https://www.npmjs.com/package/@types/node
217
217
 
@@ -359,6 +359,7 @@ class HttpAdapter {
359
359
  this.terminate("No data received");
360
360
  return;
361
361
  }
362
+ dataLength = this.contentLength || (typeof this.pipeTo === 'string' ? (0, util_1.getSize)(this.pipeTo) : 0);
362
363
  result = encoding && !pipeline ? '' : null;
363
364
  }
364
365
  this.endResponse(result, dataLength, log);
@@ -371,12 +372,11 @@ class HttpAdapter {
371
372
  }
372
373
  endResponse(result, dataLength = 0, logging = this.state.log) {
373
374
  if (logging) {
374
- const messageUnit = this.dataTime && dataLength > 0 ? (0, util_1.getTransferRate)(dataLength, (0, types_1.convertTime)(process.hrtime.bigint() - this.dataTime, false) * 1000) : undefined;
375
375
  this.instance.writeTimeProcess('HTTP' + this.httpVersion, this.opts.statusMessage || this.uri.toString(), this.startTime, {
376
376
  type: 1024,
377
377
  queue: !!this.instance.host,
378
378
  titleBgColor: !result ? 'bgBlue' : undefined,
379
- messageUnit,
379
+ messageUnit: this.formatMibs(dataLength),
380
380
  messageUnitMinWidth: 9,
381
381
  delayTime: this.delayTime,
382
382
  bypassLog: module_1.hasLogType(32768)
@@ -488,6 +488,11 @@ class HttpAdapter {
488
488
  formatStatus(value, hint) {
489
489
  return value + ': ' + (hint || (0, util_1.fromStatusCode)(value)) + ` (${this.uri.toString()})`;
490
490
  }
491
+ formatMibs(dataLength) {
492
+ if (dataLength > 0 && this.dataTime) {
493
+ return (0, util_1.getTransferRate)(dataLength, Math.max(1, (0, types_1.convertTime)(process.hrtime.bigint() - this.dataTime, false) * 1000));
494
+ }
495
+ }
491
496
  close() {
492
497
  this.closed = true;
493
498
  this.instance.reset(this);
package/index.js CHANGED
@@ -37,6 +37,7 @@ const kStatusOn = Symbol('statusOn');
37
37
  const kHeadersOn = Symbol('headersOn');
38
38
  const kAdapter = Symbol('adapter');
39
39
  const SUPPORTED_NODE20 = (0, types_1.supported)(20);
40
+ const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) && typeof zlib.createZstdDecompress === 'function';
40
41
  const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
41
42
  const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
42
43
  const HTTP = {
@@ -328,6 +329,9 @@ function decompressEncoding(value, chunkSize) {
328
329
  if (LIB_ZSTD) {
329
330
  return new LIB_ZSTD.ZstdDecompressTransform({ writableHighWaterMark: chunkSize });
330
331
  }
332
+ if (SUPPORTED_ZSTD) {
333
+ return zlib.createZstdDecompress({ chunkSize });
334
+ }
331
335
  break;
332
336
  }
333
337
  }
@@ -1433,7 +1437,7 @@ class Request extends module_1 {
1433
1437
  const baseHeaders = this.headersOf(uri);
1434
1438
  let request, ca, cert, key, ciphers, minVersion;
1435
1439
  if (getting && this.acceptEncoding && !host.localhost && !baseHeaders?.['accept-encoding']) {
1436
- (headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : '');
1440
+ (headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD || SUPPORTED_ZSTD ? ', zstd' : '');
1437
1441
  }
1438
1442
  if (posting && options.postData) {
1439
1443
  if (expectContinue) {
@@ -1767,7 +1771,7 @@ class Request extends module_1 {
1767
1771
  else {
1768
1772
  options = {};
1769
1773
  }
1770
- const headers = (0, util_1.parseOutgoingHeaders)(options.headers ||= {});
1774
+ const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
1771
1775
  for (const attr in headers) {
1772
1776
  const name = attr.toLowerCase();
1773
1777
  if (name === 'content-type' || name === 'content-length') {
@@ -1877,6 +1881,7 @@ class Request extends module_1 {
1877
1881
  options.httpVersion = 1;
1878
1882
  options.postData = data;
1879
1883
  headers['content-type'] = contentType || "text/plain";
1884
+ options.headers = headers;
1880
1885
  return this.get(uri, options);
1881
1886
  }
1882
1887
  async get(uri, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.11.3",
3
+ "version": "0.11.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": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.11.3",
24
- "@e-mc/types": "0.11.3",
23
+ "@e-mc/module": "0.11.5",
24
+ "@e-mc/types": "0.11.5",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^4.0.2",