keq 2.3.4 → 2.4.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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.4.0](https://github.com/keq-request/keq/compare/v2.3.4...v2.4.0) (2024-05-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* avoid time-consuming cloning ([5f6b773](https://github.com/keq-request/keq/commit/5f6b773a8d2a0bf9ffa529200ff4fc524b3c4090))
|
|
11
|
+
|
|
5
12
|
## [2.3.4](https://github.com/keq-request/keq/compare/v2.3.3...v2.3.4) (2024-05-14)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -3,9 +3,30 @@ export function proxyResponseMiddleware() {
|
|
|
3
3
|
await next();
|
|
4
4
|
const res = ctx.res;
|
|
5
5
|
if (res && !('response' in ctx)) {
|
|
6
|
-
|
|
7
|
-
get() {
|
|
8
|
-
|
|
6
|
+
ctx.response = new Proxy(res, {
|
|
7
|
+
get(res, prop) {
|
|
8
|
+
if (typeof prop === 'string') {
|
|
9
|
+
if (['body', 'json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
10
|
+
/**
|
|
11
|
+
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
12
|
+
* to avoid time-consuming cloning
|
|
13
|
+
*/
|
|
14
|
+
return new Proxy(res[prop], {
|
|
15
|
+
apply(target, thisArg, argArray) {
|
|
16
|
+
const mirror = res.clone();
|
|
17
|
+
return mirror[prop](...argArray);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (prop === 'body') {
|
|
22
|
+
const mirror = res.clone();
|
|
23
|
+
return mirror.body;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (typeof res[prop] === 'function') {
|
|
27
|
+
return res[prop].bind(res);
|
|
28
|
+
}
|
|
29
|
+
return res[prop];
|
|
9
30
|
},
|
|
10
31
|
});
|
|
11
32
|
}
|
|
@@ -15,9 +15,30 @@
|
|
|
15
15
|
await next();
|
|
16
16
|
const res = ctx.res;
|
|
17
17
|
if (res && !('response' in ctx)) {
|
|
18
|
-
|
|
19
|
-
get() {
|
|
20
|
-
|
|
18
|
+
ctx.response = new Proxy(res, {
|
|
19
|
+
get(res, prop) {
|
|
20
|
+
if (typeof prop === 'string') {
|
|
21
|
+
if (['body', 'json', 'text', 'arrayBuffer', 'blob', 'buffer', 'formData'].includes(prop)) {
|
|
22
|
+
/**
|
|
23
|
+
* clone when invoking body, json, text, arrayBuffer, blob, buffer, formData
|
|
24
|
+
* to avoid time-consuming cloning
|
|
25
|
+
*/
|
|
26
|
+
return new Proxy(res[prop], {
|
|
27
|
+
apply(target, thisArg, argArray) {
|
|
28
|
+
const mirror = res.clone();
|
|
29
|
+
return mirror[prop](...argArray);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (prop === 'body') {
|
|
34
|
+
const mirror = res.clone();
|
|
35
|
+
return mirror.body;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (typeof res[prop] === 'function') {
|
|
39
|
+
return res[prop].bind(res);
|
|
40
|
+
}
|
|
41
|
+
return res[prop];
|
|
21
42
|
},
|
|
22
43
|
});
|
|
23
44
|
}
|