@webqit/webflo 0.10.1 → 0.10.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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "0.10.1",
15
+ "version": "0.10.2",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -77,8 +77,8 @@ export default class Worker {
77
77
  if (!evt.request.url.startsWith('http')) return;
78
78
  const deriveInit = req => [
79
79
  'method', 'headers', 'body', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
80
- ].reduce((init, prop) => ({ [prop]: req[prop], ...init }), {});
81
- const requestInit = deriveInit(evt.request);
80
+ ].reduce((init, prop) => ({ [prop]: prop === 'body' && !req.body ? req : req[prop], ...init }), {});
81
+ const requestInit = deriveInit(evt.request.clone());
82
82
  evt.respondWith(this.go(evt.request.url, requestInit, { event: evt }));
83
83
  });
84
84
 
@@ -107,9 +107,8 @@ export default class Worker {
107
107
  init = { referrer: this.location.href, ...init };
108
108
  // ------------
109
109
  // The request object
110
- let request = this.generateRequest(url.href, init);
111
- if (detail.event instanceof self.Request) {
112
- request = detail.event.request;
110
+ let request = await this.generateRequest(url.href, init);
111
+ if (detail.event) {
113
112
  Object.defineProperty(detail.event, 'request', { value: request });
114
113
  }
115
114
  // The navigation event
@@ -133,7 +132,7 @@ export default class Worker {
133
132
  }
134
133
 
135
134
  // Generates request object
136
- generateRequest(href, init) {
135
+ async generateRequest(href, init) {
137
136
  // Now, the following is key:
138
137
  // The browser likes to use "force-cache" for "navigate" requests
139
138
  // when, for example, the back button was used.
@@ -142,7 +141,12 @@ export default class Worker {
142
141
  if (init.mode === 'navigate' && init.cache === 'force-cache') {
143
142
  init = { ...init, cache: 'default' };
144
143
  }
145
- let request = new Request(href, init);
144
+ if (init.method === 'POST' && init.body instanceof self.Request) {
145
+ init = { ...init, body: await init.body.text(), };
146
+ } else if (['GET', 'HEAD'].includes(init.method.toUpperCase()) && init.body) {
147
+ init = { ...init, body: null };
148
+ }
149
+ let request = new Request(href, init);
146
150
  return request;
147
151
  }
148
152
 
@@ -94,7 +94,7 @@ const xHttpMessage = (whatwagHttpMessage, Headers, FormData) => {
94
94
  this.bodyAttrs.jsonfied = new Promise(async (resolve, reject) => {
95
95
  var messageInstance = this, jsonfied, contentType = messageInstance.headers.get('content-type') || '';
96
96
  var type = contentType === 'application/json' || this.bodyAttrs.json ? 'json' : (
97
- contentType === 'application/x-www-form-urlencoded' || contentType.startsWith('multipart/') || this.bodyAttrs.formData ? 'formData' : (
97
+ contentType === 'application/x-www-form-urlencoded' || contentType.startsWith('multipart/form-data') || this.bodyAttrs.formData ? 'formData' : (
98
98
  contentType === 'text/plain' ? 'plain' : 'other'
99
99
  )
100
100
  );
@@ -62,6 +62,13 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
62
62
  return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
63
63
  }
64
64
 
65
+ static compat(request, url = null) {
66
+ if (request instanceof whatwagRequest) {
67
+ return Object.setPrototypeOf(request, new this);
68
+ }
69
+ return new this(url, request);
70
+ }
71
+
65
72
  };
66
73
 
67
74
  export default xRequest;