@webqit/webflo 0.11.58-0 → 0.11.59
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);
|
|
@@ -84,21 +84,20 @@ export default class Runtime extends _Runtime {
|
|
|
84
84
|
// -------------
|
|
85
85
|
// ONFETCH
|
|
86
86
|
self.addEventListener('fetch', event => {
|
|
87
|
-
console.log('[SERVICE_WORKER]: ' + event.request.url);
|
|
88
87
|
// URL schemes that might arrive here but not supported; e.g.: chrome-extension://
|
|
89
88
|
if (!event.request.url.startsWith('http')) return;
|
|
90
89
|
event.respondWith((async evt => {
|
|
91
90
|
let requestingClient = await self.clients.get(evt.clientId);
|
|
92
91
|
this.workport.setCurrentClient(requestingClient);
|
|
92
|
+
const [ url, requestInit ] = await xRequest.rip(evt.request);
|
|
93
93
|
// Now, the following is key:
|
|
94
94
|
// The browser likes to use "force-cache" for "navigate" requests, when, e.g: re-entering your site with the back button
|
|
95
95
|
// Problem here, force-cache forces out JSON not HTML as per webflo's design.
|
|
96
96
|
// So, we detect this scenerio and avoid it.
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
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';
|
|
100
99
|
}
|
|
101
|
-
return this.go(
|
|
100
|
+
return this.go(url, requestInit, { event: evt });
|
|
102
101
|
})(event));
|
|
103
102
|
});
|
|
104
103
|
|
|
@@ -136,7 +135,7 @@ export default class Runtime extends _Runtime {
|
|
|
136
135
|
// ------------
|
|
137
136
|
// The request object
|
|
138
137
|
const request = this.generateRequest(url.href, init);
|
|
139
|
-
|
|
138
|
+
if (detail.event) { Object.defineProperty(detail.event, 'request', { value: request }); }
|
|
140
139
|
// The navigation event
|
|
141
140
|
const httpEvent = new HttpEvent(request, detail, (id = null, persistent = false) => this.getSession(httpEvent, id, persistent));
|
|
142
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.arrayBuffer();
|
|
39
|
+
}
|
|
40
|
+
if (requestInit.mode === 'navigate') {
|
|
41
|
+
requestInit.mode = 'cors';
|
|
42
|
+
}
|
|
43
|
+
return [ request.url, requestInit ];
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
}
|