@webqit/fetch-plus 0.1.16 → 0.1.18

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/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "homepage": "https://fetch-plus.netlify.app/",
13
13
  "icon": "https://webqit.io/icon.svg",
14
- "version": "0.1.16",
14
+ "version": "0.1.18",
15
15
  "license": "MIT",
16
16
  "repository": {
17
17
  "type": "git",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@webqit/observer": "^3.8.19",
42
- "@webqit/port-plus": "^0.1.17",
42
+ "@webqit/port-plus": "^0.1.18",
43
43
  "@webqit/url-plus": "^0.1.4",
44
44
  "chai": "^4.3.4",
45
45
  "chai-as-promised": "^7.1.1",
@@ -38,12 +38,19 @@ export class LiveResponse extends EventTarget {
38
38
  }
39
39
 
40
40
  static hasPort(respone) {
41
+ if (respone instanceof LiveResponse && respone.#port) {
42
+ return true;
43
+ }
41
44
  const responseMeta = _meta(respone);
42
45
  return !!responseMeta.get('port')
43
46
  || !!respone.headers?.get?.(this.xHeaderName)?.trim();
44
47
  }
45
48
 
46
49
  static getPort(respone, { handshake = 1 } = {}) {
50
+ if (respone instanceof LiveResponse && respone.#port) {
51
+ return respone.#port;
52
+ }
53
+
47
54
  if (!(respone instanceof Response
48
55
  || respone instanceof LiveResponse)) {
49
56
  return;
@@ -318,6 +325,9 @@ export class LiveResponse extends EventTarget {
318
325
  const execReplaceWithResponse = async (frame, response, options) => {
319
326
  let body, port, jsonSuccess = true;
320
327
  if (response instanceof Response) {
328
+ if (response.bodyUsed) {
329
+ throw new Error('Response body already used');
330
+ }
321
331
  try {
322
332
  body = await ResponsePlus.prototype.any.call(response, { to: 'json' });
323
333
  } catch (e) {
@@ -24,7 +24,7 @@ export function messageParserMixin(superClass) {
24
24
 
25
25
  // Process body
26
26
  let body = httpMessageInit.body;
27
- let type = dataType(body);
27
+ let type = [null, undefined].includes(body) ? null : dataType(body);
28
28
 
29
29
  // Binary bodies
30
30
  if (['Blob', 'File'].includes(type)) {
@@ -56,7 +56,7 @@ export function messageParserMixin(superClass) {
56
56
  headers['content-length'] = (new Blob([body])).size;
57
57
  }
58
58
 
59
- if (!['FormData'].includes(type)
59
+ if (!['FormData', null].includes(type)
60
60
  && !['function'].includes(typeof body)
61
61
  && !headers['content-type']) {
62
62
  headers['content-type'] = 'application/octet-stream';
@@ -77,6 +77,8 @@ export function messageParserMixin(superClass) {
77
77
  'blob', 'text', 'json', 'arrayBuffer', 'bytes', 'formData'
78
78
  ].includes(to)) throw new Error(`Invalid target type specified: ${to}`);
79
79
 
80
+ if (this.body === null) return null;
81
+
80
82
  const cache = _meta(this, 'cache');
81
83
  const readAs = async (type) => {
82
84
  // 1. Direct parsing