@webqit/webflo 0.11.54 → 0.11.56-0

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.11.54",
15
+ "version": "0.11.56-0",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -276,7 +276,7 @@ export default class Runtime extends _Runtime {
276
276
  } catch(e) {
277
277
  console.error(e);
278
278
  Observer.set(this.network, 'error', { ...e, retry: () => this.go(url, init = {}, detail) });
279
- finalResponse = new xResponse(null, { status: 500, statusText: e.message });
279
+ finalResponse = new xResponse(e.message, { status: 500 });
280
280
  }
281
281
  // ------------
282
282
  // Return value
@@ -299,14 +299,14 @@ export default class Runtime extends _Runtime {
299
299
  return _response.then(async response => {
300
300
  // Stop loading status
301
301
  Observer.set(this.network, 'remote', null);
302
- return new xResponse(response);
302
+ return xResponse.compat(response);
303
303
  });
304
304
  }
305
305
 
306
306
  // Handles response object
307
307
  handleResponse(e, response) {
308
- if (typeof response === 'undefined') { response = new xResponse(undefined, { status: 404 }); }
309
- else if (!(response instanceof xResponse)) { response = new xResponse(response); }
308
+ if (!response && response !== 0) { response = new xResponse(null, { status: 404 }); }
309
+ else if (!(response instanceof xResponse)) { response = xResponse.compat(response); }
310
310
  Observer.set(this.network, 'requesting', null);
311
311
  Observer.set(this.network, 'redirecting', null);
312
312
  if (!response.redirected) {
@@ -86,18 +86,19 @@ export default class Runtime extends _Runtime {
86
86
  self.addEventListener('fetch', event => {
87
87
  // URL schemes that might arrive here but not supported; e.g.: chrome-extension://
88
88
  if (!event.request.url.startsWith('http')) return;
89
- event.respondWith((async (req, evt) => {
90
- let requestingClient = await self.clients.get(event.clientId);
89
+ event.respondWith((async evt => {
90
+ let requestingClient = await self.clients.get(evt.clientId);
91
91
  this.workport.setCurrentClient(requestingClient);
92
92
  // Now, the following is key:
93
93
  // The browser likes to use "force-cache" for "navigate" requests, when, e.g: re-entering your site with the back button
94
94
  // Problem here, force-cache forces out JSON not HTML as per webflo's design.
95
95
  // So, we detect this scenerio and avoid it.
96
- if (req.cache === 'force-cache'/* && req.mode === 'navigate' - even webflo client init call also comes with that... needs investigation */) {
97
- req = new Request(req, {cache: 'default'});
96
+ if (evt.request.cache === 'force-cache'/* && evt.request.mode === 'navigate' - even webflo client init call also comes with that... needs investigation */) {
97
+ const req = new Request(evt.request, { cache: 'default' });
98
+ Object.defineProperty(evt, 'request', { value: req });
98
99
  }
99
- return this.go(req.url, req, { event: evt });
100
- })(event.request, event));
100
+ return this.go(evt.request.url, evt.request, { event: evt });
101
+ })(event));
101
102
  });
102
103
 
103
104
  // -------------
@@ -134,9 +135,6 @@ export default class Runtime extends _Runtime {
134
135
  // ------------
135
136
  // The request object
136
137
  const request = this.generateRequest(url.href, init);
137
- if (detail.event) {
138
- Object.defineProperty(detail.event, 'request', { value: request });
139
- }
140
138
  // The navigation event
141
139
  const httpEvent = new HttpEvent(request, detail, (id = null, persistent = false) => this.getSession(httpEvent, id, persistent));
142
140
  httpEvent.port.listen(message => {
@@ -262,7 +260,7 @@ export default class Runtime extends _Runtime {
262
260
 
263
261
  // Handles response object
264
262
  handleResponse(e, response) {
265
- if (typeof response === 'undefined') { response = new xResponse(undefined, { status: 404 }); }
263
+ if (!response && response !== 0) { response = new xResponse(null, { status: 404 }); }
266
264
  else if (!(response instanceof xResponse)) { response = xResponse.compat(response); }
267
265
  return response;
268
266
  }
@@ -44,7 +44,7 @@ export default class Application extends _Application {
44
44
  return router.file(event);
45
45
  }, remoteFetch);
46
46
  if (!(response instanceof httpEvent.Response)) {
47
- response = new httpEvent.Response(response);
47
+ response = httpEvent.Response.compat(response);
48
48
  }
49
49
  // --------
50
50
  // Rendering
@@ -131,7 +131,7 @@ export default class Runtime extends _Runtime {
131
131
  // --------
132
132
  _each(clientResponse.headers.json(), (name, value) => {
133
133
  response.setHeader(name, value);
134
- });
134
+ });
135
135
  // --------
136
136
  response.statusCode = clientResponse.status;
137
137
  response.statusMessage = clientResponse.statusText;
@@ -316,17 +316,18 @@ export default class Runtime extends _Runtime {
316
316
  try {
317
317
  response = await this.remoteFetch(url2, init2);
318
318
  } catch(e) {
319
- response = new xResponse(e.message, { status: 500 });
319
+ response = new xResponse(`Reverse Proxy Error: ${e.message}`, { status: 500 });
320
320
  console.error(e);
321
321
  }
322
322
  if (this.cx.logger) {
323
- const log = this.generateLog({ url: url2.href, ...init2 }, response);
323
+ const log = this.generateLog({ url: url2.href, ...init2 }, response, true);
324
324
  this.cx.logger.log(log);
325
325
  }
326
326
  return response;
327
327
 
328
328
  }
329
329
 
330
+
330
331
  // Generates request object
331
332
  generateRequest(href, init = {}, autoHeaders = []) {
332
333
  const request = new xRequest(href, init);
@@ -384,13 +385,13 @@ export default class Runtime extends _Runtime {
384
385
  return _response.then(async response => {
385
386
  // Stop loading status
386
387
  Observer.set(this.network, 'remote', false);
387
- return new xResponse(response);
388
+ return xResponse.compat(response);
388
389
  });
389
390
  }
390
391
 
391
392
  // Handles response object
392
393
  async handleResponse(cx, e, response, autoHeaders = []) {
393
- if (!(response instanceof xResponse)) { response = new xResponse(response); }
394
+ if (!(response instanceof xResponse)) { response = xResponse.compat(response); }
394
395
  Observer.set(this.network, 'remote', false);
395
396
  Observer.set(this.network, 'error', null);
396
397
 
@@ -434,9 +435,9 @@ export default class Runtime extends _Runtime {
434
435
 
435
436
  // ----------------
436
437
  // 404
437
- if (response.meta.body === undefined) {
438
+ if (!response.meta.body && response.meta.body !== 0) {
438
439
  if (response.status === 200 || response.status === 0) {
439
- response.attrs.status = 404;
440
+ response = new xResponse(response.body, { status: 404, headers: response.headers });
440
441
  }
441
442
  return response;
442
443
  }
@@ -444,7 +445,7 @@ export default class Runtime extends _Runtime {
444
445
  // ----------------
445
446
  // Not acceptable
446
447
  if (e.request.headers.get('Accept') && !e.request.headers.accept.match(response.headers.contentType)) {
447
- response.attrs.status = 406;
448
+ response = new xResponse(response.body, { status: 406, headers: response.headers });
448
449
  return response;
449
450
  }
450
451
 
@@ -508,7 +509,7 @@ export default class Runtime extends _Runtime {
508
509
  }
509
510
 
510
511
  // Generates log
511
- generateLog(request, response) {
512
+ generateLog(request, response, isproxy = false) {
512
513
  let log = [];
513
514
  // ---------------
514
515
  const style = this.cx.logger.style || { keyword: str => str, comment: str => str, url: str => str, val: str => str, err: str => str, };
@@ -519,9 +520,11 @@ export default class Runtime extends _Runtime {
519
520
  // ---------------
520
521
  log.push(`[${style.comment((new Date).toUTCString())}]`);
521
522
  log.push(style.keyword(request.method));
523
+ if (isproxy) log.push(style.keyword('>>'));
522
524
  log.push(style.url(request.url));
523
525
  if (response.attrs.hint) log.push(`(${style.comment(response.attrs.hint)})`);
524
- if (response.headers.contentType) log.push(`(${style.comment(response.headers.contentType)})`);
526
+ const contentInfo = [response.headers.contentType, response.headers.contentLength].filter(x => x);
527
+ if (contentInfo.length) log.push(`(${style.comment(contentInfo.join('; '))})`);
525
528
  if (response.headers.get('Content-Encoding')) log.push(`(${style.comment(response.headers.get('Content-Encoding'))})`);
526
529
  if (errorCode) log.push(style.err(`${errorCode} ${response.statusText}`));
527
530
  else log.push(style.val(`${statusCode} ${response.statusText}`));
@@ -25,6 +25,7 @@ export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
25
25
  if (request instanceof Request) {
26
26
  return Object.setPrototypeOf(request, new this);
27
27
  }
28
+ return new this(request);
28
29
  }
29
30
 
30
31
  }
@@ -27,6 +27,7 @@ export default class xResponse extends mxHttpMessage(Response, xResponseHeaders)
27
27
  if (response instanceof Response) {
28
28
  return Object.setPrototypeOf(response, new this);
29
29
  }
30
+ return new this(response);
30
31
  }
31
32
 
32
33
  }
@@ -18,6 +18,10 @@ const xxHttpMessage = (whatwagHttpMessage, xHeaders) => {
18
18
  if (meta.headers) { this.headers.json(meta.headers); }
19
19
  // ------------
20
20
  let attrs = {};
21
+
22
+ if (meta.body instanceof Response) {
23
+ throw new Error('0000000000000000');
24
+ }
21
25
  Object.defineProperty(this, '_attrs', { get: () => attrs });
22
26
  Object.defineProperty(this, 'meta', { get: () => meta });
23
27
  }
@@ -45,7 +49,7 @@ const xxHttpMessage = (whatwagHttpMessage, xHeaders) => {
45
49
  }
46
50
 
47
51
  async blob() {
48
- if (this.meta.type === 'Blob') { return this.meta.body; }
52
+ if (['Blob', 'File'].includes(this.meta.type)) { return this.meta.body; }
49
53
  return super.blob();
50
54
  }
51
55
 
@@ -54,7 +58,7 @@ const xxHttpMessage = (whatwagHttpMessage, xHeaders) => {
54
58
  if (this.meta.type === 'FormData' && this.meta.body instanceof FormData) {
55
59
  formData = this.meta.body;
56
60
  } else { formData = await super.formData(); }
57
- if (formData) { xFormData.compat(formData); }
61
+ if (formData) { formData = xFormData.compat(formData); }
58
62
  return formData;
59
63
  }
60
64