@webqit/webflo 0.11.57 → 0.11.58
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
|
@@ -91,14 +91,15 @@ export default class HttpEvent {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// "with()"
|
|
94
|
-
with(url, init = {}) {
|
|
94
|
+
async with(url, init = {}) {
|
|
95
95
|
let request;
|
|
96
96
|
if (url instanceof Request) {
|
|
97
|
+
if (init instanceof Request) { [ /*url*/, init ] = await xRequest.rip(init); }
|
|
97
98
|
request = !_isEmpty(init) ? new xRequest(url, init) : url;
|
|
98
99
|
} else {
|
|
99
100
|
url = new this.URL(url, this.url.origin);
|
|
100
|
-
|
|
101
|
-
request = new xRequest(
|
|
101
|
+
[ /*url*/, init ] = await xRequest.rip(this._request);
|
|
102
|
+
request = new xRequest(url, { ...init, referrer: this.request.url });
|
|
102
103
|
}
|
|
103
104
|
return new HttpEvent(request, this.detail, this._sessionFactory, this.storageFactory);
|
|
104
105
|
}
|
package/src/runtime-pi/Router.js
CHANGED
|
@@ -85,9 +85,9 @@ export default class Router {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (_request) {
|
|
88
|
-
nextTick.event = thisTick.event.with(newDestination, _request, requestInit);
|
|
88
|
+
nextTick.event = await thisTick.event.with(newDestination, _request, requestInit);
|
|
89
89
|
} else {
|
|
90
|
-
nextTick.event = thisTick.event.with(newDestination, requestInit);
|
|
90
|
+
nextTick.event = await thisTick.event.with(newDestination, requestInit);
|
|
91
91
|
}
|
|
92
92
|
nextTick.source = thisTick.destination.join('/');
|
|
93
93
|
nextTick.destination = newDestination.split('?').shift().split('/').map(a => a.trim()).filter(a => a);
|
|
@@ -89,15 +89,15 @@ export default class Runtime extends _Runtime {
|
|
|
89
89
|
event.respondWith((async evt => {
|
|
90
90
|
let requestingClient = await self.clients.get(evt.clientId);
|
|
91
91
|
this.workport.setCurrentClient(requestingClient);
|
|
92
|
+
const [ url, requestInit ] = await xRequest.rip(evt.request);
|
|
92
93
|
// Now, the following is key:
|
|
93
94
|
// The browser likes to use "force-cache" for "navigate" requests, when, e.g: re-entering your site with the back button
|
|
94
95
|
// Problem here, force-cache forces out JSON not HTML as per webflo's design.
|
|
95
96
|
// So, we detect this scenerio and avoid it.
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
Object.defineProperty(evt, 'request', { value: req });
|
|
97
|
+
if (requestInit.cache === 'force-cache'/* && evt.request.mode === 'navigate' - even webflo client init call also comes with that... needs investigation */) {
|
|
98
|
+
requestInit.cache = 'default';
|
|
99
99
|
}
|
|
100
|
-
return this.go(
|
|
100
|
+
return this.go(url, requestInit, { event: evt });
|
|
101
101
|
})(event));
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -135,6 +135,7 @@ export default class Runtime extends _Runtime {
|
|
|
135
135
|
// ------------
|
|
136
136
|
// The request object
|
|
137
137
|
const request = this.generateRequest(url.href, init);
|
|
138
|
+
if (detail.event) { Object.defineProperty(detail.event, 'request', { value: request }); }
|
|
138
139
|
// The navigation event
|
|
139
140
|
const httpEvent = new HttpEvent(request, detail, (id = null, persistent = false) => this.getSession(httpEvent, id, persistent));
|
|
140
141
|
httpEvent.port.listen(message => {
|
|
@@ -12,7 +12,9 @@ import { formatMessage } from './util-http.js';
|
|
|
12
12
|
export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
|
|
13
13
|
|
|
14
14
|
constructor(input, init = {}, meta = {}) {
|
|
15
|
-
if (
|
|
15
|
+
if (init instanceof Request) {
|
|
16
|
+
|
|
17
|
+
} else if ('body' in init) {
|
|
16
18
|
const [ body, headers, type ] = formatMessage(init);
|
|
17
19
|
meta = { ...meta, type, body: init.body };
|
|
18
20
|
init = { ...init, body, headers };
|
|
@@ -28,4 +30,17 @@ export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
|
|
|
28
30
|
return new this(request);
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
static async rip(request) {
|
|
34
|
+
const requestInit = [
|
|
35
|
+
'method', 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
|
|
36
|
+
].reduce((init, prop) => ({ [prop]: request[prop], ...init }), {});
|
|
37
|
+
if (!['GET', 'HEAD'].includes(request.method)) {
|
|
38
|
+
requestInit.body = await request.text();
|
|
39
|
+
}
|
|
40
|
+
if (requestInit.mode === 'navigate') {
|
|
41
|
+
requestInit.mode = 'cors';
|
|
42
|
+
}
|
|
43
|
+
return [ request.url, requestInit ];
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
}
|