@webqit/webflo 0.11.39 → 0.11.40
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 +2 -3
- package/src/Context.js +3 -3
- package/src/config-pi/deployment/Layout.js +0 -1
- package/src/runtime-pi/{RuntimeClient.js → Application.js} +2 -2
- package/src/runtime-pi/HttpEvent.js +106 -0
- package/src/runtime-pi/Router.js +2 -3
- package/src/runtime-pi/Runtime.js +3 -3
- package/src/runtime-pi/client/{RuntimeClient.js → Application.js} +12 -4
- package/src/runtime-pi/client/Router.js +4 -3
- package/src/runtime-pi/client/Runtime.js +37 -59
- package/src/runtime-pi/client/Url.js +3 -3
- package/src/runtime-pi/client/Workport.js +1 -1
- package/src/runtime-pi/client/{Storage.js → createStorage.js} +3 -3
- package/src/runtime-pi/client/generate.js +5 -3
- package/src/runtime-pi/client/index.js +4 -4
- package/src/runtime-pi/client/worker/{WorkerClient.js → Application.js} +12 -8
- package/src/runtime-pi/client/worker/{Worker.js → Runtime.js} +25 -27
- package/src/runtime-pi/client/worker/index.js +6 -6
- package/src/runtime-pi/server/{RuntimeClient.js → Application.js} +8 -8
- package/src/runtime-pi/server/Router.js +3 -2
- package/src/runtime-pi/server/Runtime.js +41 -98
- package/src/runtime-pi/server/index.js +4 -4
- package/src/runtime-pi/util-http.js +70 -0
- package/src/runtime-pi/util-url.js +147 -0
- package/src/runtime-pi/xFormData.js +10 -46
- package/src/runtime-pi/xHeaders.js +2 -11
- package/src/runtime-pi/xRequest.js +29 -42
- package/src/runtime-pi/xRequestHeaders.js +20 -23
- package/src/runtime-pi/xResponse.js +19 -15
- package/src/runtime-pi/xResponseHeaders.js +41 -43
- package/src/runtime-pi/xURL.js +71 -77
- package/src/runtime-pi/xfetch.js +15 -6
- package/src/runtime-pi/xxHttpMessage.js +102 -0
- package/src/runtime-pi/client/whatwag.js +0 -27
- package/src/runtime-pi/server/whatwag.js +0 -35
- package/src/runtime-pi/util.js +0 -162
- package/src/runtime-pi/xHttpEvent.js +0 -101
- package/src/runtime-pi/xHttpMessage.js +0 -171
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _isString, _isNumeric, _isObject, _isPlainObject, _isArray, _isPlainArray, _isTypeObject, _isNumber } from '@webqit/util/js/index.js';
|
|
6
|
+
import { _before } from '@webqit/util/str/index.js';
|
|
7
|
+
import { params } from './util-url.js';
|
|
8
|
+
|
|
9
|
+
export function formatMessage(body) {
|
|
10
|
+
let type = dataType(body);
|
|
11
|
+
let headers = {};
|
|
12
|
+
if ([ 'Blob', 'File' ].includes(type)) {
|
|
13
|
+
headers = { 'Content-Type': body.type, 'Content-Length': body.size, };
|
|
14
|
+
} else if ([ 'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer' ].includes(type)) {
|
|
15
|
+
headers = { 'Content-Length': body.byteLength, };
|
|
16
|
+
} else if (type === 'json' && _isTypeObject(body)) {
|
|
17
|
+
const [ _body, isJsonfiable ] = formData(body);
|
|
18
|
+
if (isJsonfiable) {
|
|
19
|
+
body = JSON.stringify(body, (k, v) => v instanceof Error ? { ...v, message: v.message } : v);
|
|
20
|
+
headers = { 'Content-Type': 'application/json', 'Content-Length': (new Blob([ body ])).size, };
|
|
21
|
+
} else {
|
|
22
|
+
body = _body;
|
|
23
|
+
type = 'FormData';
|
|
24
|
+
}
|
|
25
|
+
} else if (type === 'json') {
|
|
26
|
+
headers = { 'Content-Length': (body + '').length, };
|
|
27
|
+
}
|
|
28
|
+
return [ body, headers, type ];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formData(data = {}) {
|
|
32
|
+
const formData = this instanceof FormData ? this : new FormData;
|
|
33
|
+
let isJsonfiable = true;
|
|
34
|
+
if (arguments.length) {
|
|
35
|
+
params.reduceValue(data, '', (value, contextPath, suggestedKeys = undefined) => {
|
|
36
|
+
if (suggestedKeys) {
|
|
37
|
+
const isJson = dataType(value) === 'json';
|
|
38
|
+
isJsonfiable = isJsonfiable && isJson;
|
|
39
|
+
return isJson && suggestedKeys;
|
|
40
|
+
}
|
|
41
|
+
formData.append(contextPath, value);
|
|
42
|
+
});
|
|
43
|
+
return [ formData, isJsonfiable ];
|
|
44
|
+
}
|
|
45
|
+
let json;
|
|
46
|
+
for (let [ name, value ] of formData.entries()) {
|
|
47
|
+
if (!json) { json = _isNumeric(_before(name, '[')) ? [] : {}; }
|
|
48
|
+
const isJson = dataType(value) === 'json';
|
|
49
|
+
isJsonfiable = isJsonfiable && isJson;
|
|
50
|
+
if (value === 'false') { value = false; }
|
|
51
|
+
if (value === 'true') { value = true; }
|
|
52
|
+
if (value === 'null') { value = null; }
|
|
53
|
+
if (value === 'undefined') { value = undefined; }
|
|
54
|
+
params.set(json, name, value);
|
|
55
|
+
}
|
|
56
|
+
return [ json, isJsonfiable ];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function dataType(value) {
|
|
60
|
+
if (_isString(value) || _isNumber(value) || value === null) return 'json';
|
|
61
|
+
if (!_isTypeObject(value)) return;
|
|
62
|
+
const toStringTag = value[Symbol.toStringTag];
|
|
63
|
+
const type = [
|
|
64
|
+
'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream', 'ReadableStream'
|
|
65
|
+
].reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
|
|
66
|
+
if (type) return type;
|
|
67
|
+
if ((_isObject(value) && _isPlainObject(value)) || (_isArray(value) && _isPlainArray(value)) || 'toString' in value) {
|
|
68
|
+
return 'json';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _isString, _isNumeric, _isArray, _isTypeObject } from '@webqit/util/js/index.js';
|
|
6
|
+
if (typeof URLPattern === 'undefined') {
|
|
7
|
+
await import('urlpattern-polyfill');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const params = {
|
|
11
|
+
// Parse a search params string into an object
|
|
12
|
+
parse(str, delim = '&') {
|
|
13
|
+
str = str || '';
|
|
14
|
+
const target = {};
|
|
15
|
+
(str.startsWith('?') ? str.substr(1) : str)
|
|
16
|
+
.split(delim).filter(q => q).map(q => q.split('=').map(q => q.trim()))
|
|
17
|
+
.forEach(q => this.set(target, q[0], decodeURIComponent(q[1])));
|
|
18
|
+
return target;
|
|
19
|
+
},
|
|
20
|
+
// Stringify an object into a search params string
|
|
21
|
+
stringify(targetObject, delim = '&') {
|
|
22
|
+
const q = [];
|
|
23
|
+
Object.keys(targetObject).forEach(key => {
|
|
24
|
+
this.reduceValue(targetObject[key], key, (_value, _pathNotation, suggestedKeys = undefined) => {
|
|
25
|
+
if (suggestedKeys) return suggestedKeys;
|
|
26
|
+
q.push(`${_pathNotation}=${encodeURIComponent(_value)}`);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return q.join(delim);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// Get value by path notation
|
|
33
|
+
get(targetObject, pathNotation) {
|
|
34
|
+
return this.reducePath(pathNotation, targetObject, (key, _targetObject) => {
|
|
35
|
+
if (!_targetObject && _targetObject !== 0) return;
|
|
36
|
+
return _targetObject[key];
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
// Set value by path notation
|
|
40
|
+
set(targetObject, pathNotation, value) {
|
|
41
|
+
this.reducePath(pathNotation, targetObject, function(_key, _targetObject, suggestedBranch = undefined) {
|
|
42
|
+
let _value = value;
|
|
43
|
+
if (suggestedBranch) { _value = suggestedBranch; }
|
|
44
|
+
if (_key === '' && _isArray(_targetObject)) {
|
|
45
|
+
_targetObject.push(_value);
|
|
46
|
+
} else {
|
|
47
|
+
_targetObject[_key] = _value;
|
|
48
|
+
}
|
|
49
|
+
return _value;
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// Resolve a value to its leaf nodes
|
|
54
|
+
reduceValue(value, contextPath, callback) {
|
|
55
|
+
if (_isTypeObject(value)) {
|
|
56
|
+
let suggestedKeys = Object.keys(value);
|
|
57
|
+
let keys = callback(value, contextPath, suggestedKeys);
|
|
58
|
+
if (_isArray(keys)) {
|
|
59
|
+
return keys.forEach(key => {
|
|
60
|
+
this.reduceValue(value[key], contextPath ? `${contextPath}[${key}]` : key, callback);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
callback(value, contextPath);
|
|
65
|
+
},
|
|
66
|
+
// Resolve a path to its leaf index
|
|
67
|
+
reducePath(pathNotation, contextObject, callback) {
|
|
68
|
+
if (_isString(pathNotation) && pathNotation.endsWith(']') && _isTypeObject(contextObject)) {
|
|
69
|
+
let [ key, ...rest ] = pathNotation.split('[');
|
|
70
|
+
if (_isNumeric(key)) { key = parseInt(key); }
|
|
71
|
+
rest = rest.join('[').replace(']', '');
|
|
72
|
+
let branch;
|
|
73
|
+
if (key in contextObject) {
|
|
74
|
+
branch = contextObject[key];
|
|
75
|
+
} else {
|
|
76
|
+
let suggestedBranch = rest === '' || _isNumeric(rest.split('[')[0]) ? [] : {};
|
|
77
|
+
branch = callback(key, contextObject, suggestedBranch);
|
|
78
|
+
}
|
|
79
|
+
return this.reducePath(rest, branch, callback);
|
|
80
|
+
}
|
|
81
|
+
if (_isNumeric(pathNotation)) { pathNotation = parseInt(pathNotation); }
|
|
82
|
+
return callback(pathNotation, contextObject);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const path = {
|
|
87
|
+
join(/* path segments */) {
|
|
88
|
+
// Split the inputs into a list of path commands.
|
|
89
|
+
var parts = [], backsteps = 0;
|
|
90
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
91
|
+
parts = parts.concat(arguments[i].split("/"));
|
|
92
|
+
}
|
|
93
|
+
// Interpret the path commands to get the new resolved path.
|
|
94
|
+
var newParts = [];
|
|
95
|
+
for (i = 0, l = parts.length; i < l; i++) {
|
|
96
|
+
var part = parts[i];
|
|
97
|
+
// Remove leading and trailing slashes
|
|
98
|
+
// Also remove "." segments
|
|
99
|
+
if (!part || part === ".") continue;
|
|
100
|
+
// Interpret ".." to pop the last segment
|
|
101
|
+
if (part === "..") {
|
|
102
|
+
if (!newParts.length) backsteps ++;
|
|
103
|
+
else newParts.pop();
|
|
104
|
+
}
|
|
105
|
+
// Push new path segments.
|
|
106
|
+
else newParts.push(part);
|
|
107
|
+
}
|
|
108
|
+
// Preserve the initial slash if there was one.
|
|
109
|
+
if (parts[0] === "") newParts.unshift("");
|
|
110
|
+
// Turn back into a single string path.
|
|
111
|
+
return '../'.repeat(backsteps) + newParts.join("/") || (newParts.length ? "/" : ".");
|
|
112
|
+
},
|
|
113
|
+
// A simple function to get the dirname of a path
|
|
114
|
+
// Trailing slashes are ignored. Leading slash is preserved.
|
|
115
|
+
dirname(path) {
|
|
116
|
+
return this.join(path, "..");
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const pattern = (pattern, baseUrl = null) => ({
|
|
121
|
+
pattern: new URLPattern(pattern, baseUrl),
|
|
122
|
+
isPattern() {
|
|
123
|
+
return Object.keys(this.pattern.keys || {}).some(compName => this.pattern.keys[compName].length);
|
|
124
|
+
},
|
|
125
|
+
test(...args) { return this.pattern.test(...args) },
|
|
126
|
+
exec(...args) {
|
|
127
|
+
let components = this.pattern.exec(...args);
|
|
128
|
+
if (!components) return;
|
|
129
|
+
components.vars = Object.keys(this.pattern.keys).reduce(({ named, unnamed }, compName) => {
|
|
130
|
+
this.pattern.keys[compName].forEach(key => {
|
|
131
|
+
let value = components[compName].groups[key.name];
|
|
132
|
+
if (typeof key.name === 'number') {
|
|
133
|
+
unnamed.push(value);
|
|
134
|
+
} else {
|
|
135
|
+
named[key.name] = value;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return { named, unnamed };
|
|
139
|
+
}, { named: {}, unnamed: [] });
|
|
140
|
+
components.render = str => {
|
|
141
|
+
return str.replace(/\$(\$|[0-9A-Z]+)/gi, (a, b) => {
|
|
142
|
+
return b === '$' ? '$' : (_isNumeric(b) ? components.vars.unnamed[b - 1] : components.vars.named[b]) || '';
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return components;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
@@ -2,59 +2,23 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import { _before } from '@webqit/util/str/index.js';
|
|
7
|
-
import { wwwFormSet, wwwFormPathSerializeCallback } from './util.js';
|
|
5
|
+
import { formData } from './util-http.js';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* The _Headers Mixin
|
|
11
9
|
*/
|
|
12
|
-
|
|
10
|
+
export default class xFormData extends FormData {
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const formDataType = formDataType(value);
|
|
18
|
-
if ((callback && callback(value, name, formDataType)) || (!callback && !formDataType)) {
|
|
19
|
-
formData1.append(name, value);
|
|
20
|
-
} else {
|
|
21
|
-
formData2.append(name, value);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return [ formData1, formData2 ];
|
|
12
|
+
json(data = {}) {
|
|
13
|
+
const result = formData.call(this, ...arguments);
|
|
14
|
+
return result[0];
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!callback || callback(_wwwFormPath, _value, _isTypeObject(_value))) {
|
|
32
|
-
this.append(_wwwFormPath, _value);
|
|
33
|
-
}
|
|
34
|
-
}, value => !formDataType(value));
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
var jsonBuild; // We'll dynamically determine if this should be an array or an object
|
|
39
|
-
for (var [ name, value ] of this.entries()) {
|
|
40
|
-
if (!jsonBuild) {
|
|
41
|
-
jsonBuild = _isNumeric(_before(name, '[')) ? [] : {};
|
|
42
|
-
}
|
|
43
|
-
wwwFormSet(jsonBuild, name, value);
|
|
17
|
+
static compat(formData) {
|
|
18
|
+
if (formData instanceof this) return formData;
|
|
19
|
+
if (formData instanceof FormData) {
|
|
20
|
+
return Object.setPrototypeOf(formData, new this);
|
|
44
21
|
}
|
|
45
|
-
return jsonBuild;
|
|
46
22
|
}
|
|
47
23
|
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default xFormData;
|
|
51
|
-
|
|
52
|
-
export const formDataType = (value, list = null) => {
|
|
53
|
-
if (!_isTypeObject(value)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const toStringTag = value[Symbol.toStringTag];
|
|
57
|
-
return (list || [
|
|
58
|
-
'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream'
|
|
59
|
-
]).reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
|
|
60
|
-
};
|
|
24
|
+
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _after, _beforeLast } from "@webqit/util/str/index.js";
|
|
6
|
-
import { _isString, _getType, _isObject, _isFunction } from "@webqit/util/js/index.js";
|
|
7
|
-
import { _isTypeObject } from '@webqit/util/js/index.js';
|
|
8
|
-
|
|
9
2
|
/**
|
|
10
3
|
* The xHeaders Mixin
|
|
11
4
|
*/
|
|
12
|
-
|
|
5
|
+
export default class xHeaders extends Headers {
|
|
13
6
|
|
|
14
7
|
// construct
|
|
15
8
|
constructor(definition = {}) {
|
|
16
9
|
const cookies = definition.cookies;
|
|
17
10
|
delete definition.cookies;
|
|
18
11
|
// -----------------
|
|
19
|
-
if (definition instanceof
|
|
12
|
+
if (definition instanceof Headers) {
|
|
20
13
|
// It's another Headers instance
|
|
21
14
|
super(definition);
|
|
22
15
|
} else {
|
|
@@ -140,8 +133,6 @@ const xHeaders = whatwagHeaders => class extends whatwagHeaders {
|
|
|
140
133
|
|
|
141
134
|
}
|
|
142
135
|
|
|
143
|
-
export default xHeaders;
|
|
144
|
-
|
|
145
136
|
function getAllPropertyDescriptors(obj) {
|
|
146
137
|
if (!obj) {
|
|
147
138
|
return Object.create(null);
|
|
@@ -2,46 +2,47 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { formatMessage } from './util-http.js';
|
|
6
|
+
import mxHttpMessage from './xxHttpMessage.js';
|
|
7
|
+
import xRequestHeaders from './xRequestHeaders.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* The xRequest Mixin
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
|
|
11
13
|
|
|
12
14
|
constructor(input, init = {}) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if ((input instanceof whatwagRequest)) {
|
|
15
|
+
let meta = {};
|
|
16
|
+
if ((input instanceof Request)) {
|
|
16
17
|
// On method change...
|
|
17
18
|
if (init.method && input.method !== init.method.toUpperCase() && [ 'GET', 'HEAD' ].includes(init.method.toUpperCase())) {
|
|
18
19
|
// Body must not be inherited.
|
|
19
20
|
input = input.url;
|
|
21
|
+
init = { ...init };
|
|
20
22
|
// We should now simply copy attributes
|
|
21
23
|
[ 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity' ].forEach(attr => {
|
|
22
|
-
if (!(attr in init)) {
|
|
23
|
-
init[attr] = input[attr];
|
|
24
|
-
}
|
|
24
|
+
if (!(attr in init)) { init[attr] = input[attr]; }
|
|
25
25
|
});
|
|
26
|
-
} else {
|
|
27
|
-
// Inherit bodyAttrs
|
|
28
|
-
bodyAttrs = input.bodyAttrs || {};
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
// Init can contain "already-parsed request content"
|
|
32
|
-
if (('body' in init)) {
|
|
33
|
-
bodyAttrs = encodeBody(init.body, FormData, Blob);
|
|
34
|
-
init.body = bodyAttrs.body;
|
|
35
|
-
}
|
|
36
28
|
let isNavigateMode;
|
|
37
|
-
if (init
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
if (!(init instanceof Request)) {
|
|
30
|
+
// Init can contain "already-parsed request content"
|
|
31
|
+
if (('body' in init) && !(init.headers instanceof Headers)) {
|
|
32
|
+
const [ body, headers, type ] = formatMessage(init.body);
|
|
33
|
+
meta = { type, body: init.body };
|
|
34
|
+
init = { ...init, body, headers: { ...headers, ...(init.headers || {}), } };
|
|
35
|
+
}
|
|
36
|
+
if (init.mode === 'navigate') {
|
|
37
|
+
isNavigateMode = true;
|
|
38
|
+
init = { ...init };
|
|
39
|
+
delete init.mode;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// ---------------
|
|
43
|
+
super(input, init, meta);
|
|
44
|
+
// ---------------
|
|
43
45
|
if (isNavigateMode) {
|
|
44
|
-
// Through the backdoor
|
|
45
46
|
this.attrs.mode = 'navigate';
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -50,16 +51,11 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
|
|
|
50
51
|
return 'mode' in this.attrs ? this.attrs.mode : super.mode;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return 'destination' in this.attrs ? this.attrs.destination : super.destination;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get referrer() {
|
|
62
|
-
return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
|
|
54
|
+
static compat(request) {
|
|
55
|
+
if (request instanceof this) return request;
|
|
56
|
+
if (request instanceof Request) {
|
|
57
|
+
return Object.setPrototypeOf(request, new this);
|
|
58
|
+
}
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
static async rip(request) {
|
|
@@ -72,13 +68,4 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
|
|
|
72
68
|
return [ request.url, requestInit ];
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
if (request instanceof this) return request;
|
|
77
|
-
if (request instanceof whatwagRequest) {
|
|
78
|
-
return Object.setPrototypeOf(request, new this);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export default xRequest;
|
|
71
|
+
}
|
|
@@ -4,34 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { _after } from "@webqit/util/str/index.js";
|
|
6
6
|
import { _from as _arrFrom } from "@webqit/util/arr/index.js";
|
|
7
|
-
import {
|
|
8
|
-
import { wwwFormUnserialize } from './util.js';
|
|
7
|
+
import { params } from './util-url.js';
|
|
9
8
|
import xHeaders from './xHeaders.js';
|
|
10
9
|
import xCookies from './Cookies.js';
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* Cookies
|
|
14
|
-
*/
|
|
15
|
-
class Cookies extends xCookies {
|
|
16
|
-
|
|
17
|
-
parse(str) {
|
|
18
|
-
return wwwFormUnserialize(str, {}, ';');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
parseEntry(str) {
|
|
22
|
-
return str.trim().split('=');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
stringifyEntry(cookieBody) {
|
|
26
|
-
return cookieBody;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
11
|
/**
|
|
32
12
|
* The xHeaders Mixin
|
|
33
13
|
*/
|
|
34
|
-
|
|
14
|
+
export default class xRequestHeaders extends xHeaders {
|
|
35
15
|
|
|
36
16
|
get cookieHeaderName() {
|
|
37
17
|
return 'Cookie';
|
|
@@ -109,4 +89,21 @@ const xRequestHeaders = NativeHeaders => class extends xHeaders(NativeHeaders) {
|
|
|
109
89
|
|
|
110
90
|
}
|
|
111
91
|
|
|
112
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Cookies
|
|
94
|
+
*/
|
|
95
|
+
class Cookies extends xCookies {
|
|
96
|
+
|
|
97
|
+
parse(str) {
|
|
98
|
+
return params.parse(str, ';');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
parseEntry(str) {
|
|
102
|
+
return str.trim().split('=');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
stringifyEntry(cookieBody) {
|
|
106
|
+
return cookieBody;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
@@ -2,31 +2,37 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { formatMessage } from './util-http.js';
|
|
6
|
+
import mxHttpMessage from './xxHttpMessage.js';
|
|
7
|
+
import xResponseHeaders from './xResponseHeaders.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* The xResponse Mixin
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
export default class xResponse extends mxHttpMessage(Response, xResponseHeaders) {
|
|
11
13
|
|
|
12
14
|
// construct
|
|
13
|
-
constructor(body =
|
|
14
|
-
let
|
|
15
|
+
constructor(body = undefined, init = {}) {
|
|
16
|
+
let meta = {}, isResponseInput;
|
|
15
17
|
if (arguments.length) {
|
|
16
|
-
if (body instanceof
|
|
18
|
+
if (body instanceof Response) {
|
|
17
19
|
isResponseInput = body;
|
|
18
20
|
// Inherit init
|
|
19
21
|
init = { status: body.status, statusText: body.statusText, headers: body.headers, ...init };
|
|
20
22
|
if (body.status === 0) delete init.status;
|
|
21
|
-
// Inherit
|
|
22
|
-
|
|
23
|
+
// Inherit meta and body
|
|
24
|
+
meta = body.meta || {};
|
|
23
25
|
body = body.body;
|
|
24
|
-
} else {
|
|
25
|
-
|
|
26
|
-
body =
|
|
26
|
+
} else if (!(init.headers instanceof Headers)) {
|
|
27
|
+
let headers, type, _body = body;
|
|
28
|
+
[ body, headers, type ] = formatMessage(body);
|
|
29
|
+
meta = { type, body: _body };
|
|
30
|
+
init = { ...init, headers: { ...headers, ...(init.headers || {}), } };
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
// ---------------
|
|
34
|
+
super(body, init, meta);
|
|
35
|
+
// ---------------
|
|
30
36
|
if (isResponseInput) {
|
|
31
37
|
// Through the backdoor
|
|
32
38
|
this.attrs.url = isResponseInput.url;
|
|
@@ -59,11 +65,9 @@ const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xH
|
|
|
59
65
|
|
|
60
66
|
static compat(response) {
|
|
61
67
|
if (response instanceof this) return response;
|
|
62
|
-
if (response instanceof
|
|
68
|
+
if (response instanceof Response) {
|
|
63
69
|
return Object.setPrototypeOf(response, new this);
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default xResponse;
|
|
73
|
+
}
|
|
@@ -4,53 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { _after, _beforeLast } from "@webqit/util/str/index.js";
|
|
6
6
|
import { _isString, _getType, _isObject } from "@webqit/util/js/index.js";
|
|
7
|
-
import
|
|
7
|
+
import xHeaders from './xHeaders.js';
|
|
8
8
|
import xCookies from './Cookies.js';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Cookies
|
|
12
|
-
*/
|
|
13
|
-
class Cookies extends xCookies {
|
|
14
|
-
|
|
15
|
-
parse(cookieStr) {
|
|
16
|
-
const obj = {};
|
|
17
|
-
cookieStr && cookieStr.split(',').forEach(str => {
|
|
18
|
-
let [ cookieName, definition ] = this.parseEntry(str);
|
|
19
|
-
obj[cookieName] = definition;
|
|
20
|
-
});
|
|
21
|
-
return obj;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
parseEntry(str) {
|
|
25
|
-
let [ cookieDefinition, attrsStr ] = str.split(';');
|
|
26
|
-
let [ cookieName, cookieValue ] = cookieDefinition.trim().split('=');
|
|
27
|
-
let attrs = { value: cookieValue, };
|
|
28
|
-
attrsStr && (attrsStr || '').split(/\;/g).map(attrStr => attrStr.trim().split('=')).forEach(attrsArr => {
|
|
29
|
-
attrs[attrsArr[0][0].toLowerCase() + attrsArr[0].substring(1).replace('-', '')] = attrsArr.length === 1 ? true : attrsArr[1];
|
|
30
|
-
});
|
|
31
|
-
return [ cookieName, attrs ];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
stringifyEntry(cookieBody) {
|
|
35
|
-
if (_isObject(cookieBody)) {
|
|
36
|
-
let attrsArr = [ cookieBody.value ];
|
|
37
|
-
for (let attrName in cookieBody) {
|
|
38
|
-
if (attrName === 'value') continue;
|
|
39
|
-
let _attrName = attrName[0].toUpperCase() + attrName.substring(1);
|
|
40
|
-
if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
|
|
41
|
-
attrsArr.push(cookieBody[attrName] === true ? _attrName : `${_attrName}=${cookieBody[attrName]}`);
|
|
42
|
-
}
|
|
43
|
-
cookieBody = attrsArr.join(';');
|
|
44
|
-
}
|
|
45
|
-
return cookieBody;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
/**
|
|
51
11
|
* The _Headers Mixin
|
|
52
12
|
*/
|
|
53
|
-
|
|
13
|
+
export default class xResponseHeaders extends xHeaders {
|
|
54
14
|
|
|
55
15
|
get cookieHeaderName() {
|
|
56
16
|
return 'Set-Cookie';
|
|
@@ -116,4 +76,42 @@ const _ResponseHeaders = NativeHeaders => class extends _Headers(NativeHeaders)
|
|
|
116
76
|
|
|
117
77
|
}
|
|
118
78
|
|
|
119
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Cookies
|
|
81
|
+
*/
|
|
82
|
+
class Cookies extends xCookies {
|
|
83
|
+
|
|
84
|
+
parse(cookieStr) {
|
|
85
|
+
const obj = {};
|
|
86
|
+
cookieStr && cookieStr.split(',').forEach(str => {
|
|
87
|
+
let [ cookieName, definition ] = this.parseEntry(str);
|
|
88
|
+
obj[cookieName] = definition;
|
|
89
|
+
});
|
|
90
|
+
return obj;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
parseEntry(str) {
|
|
94
|
+
let [ cookieDefinition, attrsStr ] = str.split(';');
|
|
95
|
+
let [ cookieName, cookieValue ] = cookieDefinition.trim().split('=');
|
|
96
|
+
let attrs = { value: cookieValue, };
|
|
97
|
+
attrsStr && (attrsStr || '').split(/\;/g).map(attrStr => attrStr.trim().split('=')).forEach(attrsArr => {
|
|
98
|
+
attrs[attrsArr[0][0].toLowerCase() + attrsArr[0].substring(1).replace('-', '')] = attrsArr.length === 1 ? true : attrsArr[1];
|
|
99
|
+
});
|
|
100
|
+
return [ cookieName, attrs ];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
stringifyEntry(cookieBody) {
|
|
104
|
+
if (_isObject(cookieBody)) {
|
|
105
|
+
let attrsArr = [ cookieBody.value ];
|
|
106
|
+
for (let attrName in cookieBody) {
|
|
107
|
+
if (attrName === 'value') continue;
|
|
108
|
+
let _attrName = attrName[0].toUpperCase() + attrName.substring(1);
|
|
109
|
+
if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
|
|
110
|
+
attrsArr.push(cookieBody[attrName] === true ? _attrName : `${_attrName}=${cookieBody[attrName]}`);
|
|
111
|
+
}
|
|
112
|
+
cookieBody = attrsArr.join(';');
|
|
113
|
+
}
|
|
114
|
+
return cookieBody;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|