@e-mc/request 0.13.5 → 0.13.6

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.13.5/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.6/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -252,9 +252,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
252
252
 
253
253
  ## References
254
254
 
255
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/http.d.ts
256
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/request.d.ts
257
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/settings.d.ts
255
+ - https://www.unpkg.com/@e-mc/types@0.13.6/lib/http.d.ts
256
+ - https://www.unpkg.com/@e-mc/types@0.13.6/lib/request.d.ts
257
+ - https://www.unpkg.com/@e-mc/types@0.13.6/lib/settings.d.ts
258
258
 
259
259
  * https://www.npmjs.com/package/@types/node
260
260
 
@@ -417,6 +417,9 @@ class HttpAdapter {
417
417
  }
418
418
  else if (++this.redirects <= this.redirectLimit) {
419
419
  this.abortResponse();
420
+ if (this.opts.method?.toUpperCase() === 'PUT' && statusCode !== 307 && statusCode !== 308) {
421
+ this.#options.method = 'GET';
422
+ }
420
423
  this.setOpts((0, util_1.fromURL)(this.opts.url, location));
421
424
  this.init();
422
425
  }
@@ -6,14 +6,11 @@ const HOST_STREAM = new Map();
6
6
  const HOST_HTTP_1_1 = [];
7
7
  const HOST_ALPN_H2C = [];
8
8
  const HOST_ALPN_H2 = [];
9
- (function () {
10
- const nic = require('node:os').networkInterfaces();
11
- for (const name in nic) {
12
- for (const { address } of nic[name].filter(item => item.internal)) {
13
- HOST_LOCAL.add(address);
14
- }
9
+ for (const network of Object.entries(require('node:os').networkInterfaces())) {
10
+ for (const { address } of network[1].filter(item => item.internal)) {
11
+ HOST_LOCAL.add(address);
15
12
  }
16
- })();
13
+ }
17
14
  class HttpHost {
18
15
  static normalizeOrigin(value) {
19
16
  return (value = value.trim()).replace(/\/+$/, '') + (!/:\d+$/.test(value) ? ':' + (value.startsWith('https') ? '443' : '80') : '');
package/index.js CHANGED
@@ -850,9 +850,6 @@ class Request extends module_1 {
850
850
  this.readTimeout = (value = (0, util_1.fromSeconds)(read_timeout)) >= 0 ? value : READ_TIMEOUT;
851
851
  this.keepAlive = typeof (value = agent?.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
852
852
  this.acceptEncoding = typeof (value = use?.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
853
- if ((value = (0, util_1.asInt)(use?.http_version)) === 1 || value === 2) {
854
- this.#httpVersion = value;
855
- }
856
853
  this.#ipVersion = (value = (0, util_1.asInt)(data.dns?.family)) && (value === 4 || value === 6) ? value : 0;
857
854
  if ((value = (0, util_1.fromSeconds)(agent?.timeout)) >= 0) {
858
855
  this.#agentTimeout = value;
@@ -861,6 +858,9 @@ class Request extends module_1 {
861
858
  this.#agentTimeout = AGENT_TIMEOUT;
862
859
  value = undefined;
863
860
  }
861
+ if ((value = (0, util_1.asInt)(use?.http_version)) === 1 || value === 2) {
862
+ this.#httpVersion = value;
863
+ }
864
864
  const proxy = getProxySettings(data, value);
865
865
  if (proxy) {
866
866
  this.proxy = proxy;
@@ -890,8 +890,8 @@ class Request extends module_1 {
890
890
  this.readTimeout = READ_TIMEOUT;
891
891
  this.keepAlive = KEEP_ALIVE;
892
892
  this.acceptEncoding = ACCEPT_ENCODING;
893
- this.#agentTimeout = AGENT_TIMEOUT;
894
893
  this.#ipVersion = DNS.FAMILY;
894
+ this.#agentTimeout = AGENT_TIMEOUT;
895
895
  }
896
896
  this.module = data;
897
897
  }
@@ -1739,7 +1739,7 @@ class Request extends module_1 {
1739
1739
  return { ...options, host, url };
1740
1740
  }
1741
1741
  open(uri, options) {
1742
- let { host, url, httpVersion, method = 'GET', search, encoding, format, headers: outgoing, socketPath, expectContinue = false, timeout = this._config.connectTimeout, outStream } = options, headers = (0, util_1.parseOutgoingHeaders)(outgoing), getting = false, posting = false;
1742
+ let { host, url, httpVersion, method = 'GET', search, encoding, format, socketPath, expectContinue = false, timeout = this._config.connectTimeout, outStream } = options, headers = (0, util_1.parseOutgoingHeaders)(options.headers), getting = false, posting = false;
1743
1743
  switch (method = method.toUpperCase()) {
1744
1744
  case 'GET':
1745
1745
  case 'DELETE':
@@ -2196,7 +2196,7 @@ class Request extends module_1 {
2196
2196
  }
2197
2197
  }
2198
2198
  for (let { name, data: target, value, contentType: type, filename } of parts) {
2199
- if (!(0, types_1.isString)(name)) {
2199
+ if (!name) {
2200
2200
  continue;
2201
2201
  }
2202
2202
  if (target) {
@@ -2282,10 +2282,9 @@ class Request extends module_1 {
2282
2282
  }
2283
2283
  const singleton = this.#singleton;
2284
2284
  const verbose = !opts.silent && !singleton || opts.silent === false;
2285
- const log = verbose && LOG_HTTP && LOG_TIMEPROCESS;
2286
2285
  const state = Object.freeze({
2287
2286
  verbose,
2288
- log,
2287
+ log: verbose && LOG_HTTP && LOG_TIMEPROCESS,
2289
2288
  singleton,
2290
2289
  config: this._config
2291
2290
  });
@@ -2302,10 +2301,11 @@ class Request extends module_1 {
2302
2301
  this.#downloading.delete(ac);
2303
2302
  adapter.abortController = null;
2304
2303
  }
2305
- return;
2306
2304
  }
2307
- this.#pendingDns = Object.create(null);
2308
- this.#downloading.clear();
2305
+ else {
2306
+ this.#pendingDns = Object.create(null);
2307
+ this.#downloading.clear();
2308
+ }
2309
2309
  }
2310
2310
  close() {
2311
2311
  const session = this.#session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.13.5",
3
+ "version": "0.13.6",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/module": "0.13.5",
23
- "@e-mc/types": "0.13.5",
22
+ "@e-mc/module": "0.13.6",
23
+ "@e-mc/types": "0.13.6",
24
24
  "combined-stream": "^1.0.8",
25
25
  "js-yaml": "^4.1.1",
26
26
  "picomatch": "^4.0.3",