@tauri-apps/plugin-http 2.0.0-beta.6 → 2.0.0-beta.8
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/dist-js/index.cjs +28 -8
- package/dist-js/index.js +28 -8
- package/package.json +2 -2
package/dist-js/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ var core = require('@tauri-apps/api/core');
|
|
|
28
28
|
*
|
|
29
29
|
* @module
|
|
30
30
|
*/
|
|
31
|
+
const ERROR_REQUEST_CANCELLED = "Request canceled";
|
|
31
32
|
/**
|
|
32
33
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
|
33
34
|
* `Response` to that `Request`, whether it is successful or not.
|
|
@@ -43,6 +44,11 @@ var core = require('@tauri-apps/api/core');
|
|
|
43
44
|
* @since 2.0.0
|
|
44
45
|
*/
|
|
45
46
|
async function fetch(input, init) {
|
|
47
|
+
// abort early here if needed
|
|
48
|
+
const signal = init?.signal;
|
|
49
|
+
if (signal?.aborted) {
|
|
50
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
51
|
+
}
|
|
46
52
|
const maxRedirections = init?.maxRedirections;
|
|
47
53
|
const connectTimeout = init?.connectTimeout;
|
|
48
54
|
const proxy = init?.proxy;
|
|
@@ -52,7 +58,6 @@ async function fetch(input, init) {
|
|
|
52
58
|
delete init.connectTimeout;
|
|
53
59
|
delete init.proxy;
|
|
54
60
|
}
|
|
55
|
-
const signal = init?.signal;
|
|
56
61
|
const headers = init?.headers
|
|
57
62
|
? init.headers instanceof Headers
|
|
58
63
|
? init.headers
|
|
@@ -80,6 +85,10 @@ async function fetch(input, init) {
|
|
|
80
85
|
// eslint-disable-next-line
|
|
81
86
|
typeof val === "string" ? val : val.toString(),
|
|
82
87
|
]);
|
|
88
|
+
// abort early here if needed
|
|
89
|
+
if (signal?.aborted) {
|
|
90
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
91
|
+
}
|
|
83
92
|
const rid = await core.invoke("plugin:http|fetch", {
|
|
84
93
|
clientConfig: {
|
|
85
94
|
method: req.method,
|
|
@@ -91,11 +100,15 @@ async function fetch(input, init) {
|
|
|
91
100
|
proxy,
|
|
92
101
|
},
|
|
93
102
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
const abort = () => core.invoke("plugin:http|fetch_cancel", { rid });
|
|
104
|
+
// abort early here if needed
|
|
105
|
+
if (signal?.aborted) {
|
|
106
|
+
// we don't care about the result of this proimse
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
108
|
+
abort();
|
|
109
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
110
|
+
}
|
|
111
|
+
signal?.addEventListener("abort", () => abort);
|
|
99
112
|
const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await core.invoke("plugin:http|fetch_send", {
|
|
100
113
|
rid,
|
|
101
114
|
});
|
|
@@ -107,12 +120,19 @@ async function fetch(input, init) {
|
|
|
107
120
|
: body instanceof Array && body.length > 0
|
|
108
121
|
? new Uint8Array(body)
|
|
109
122
|
: null, {
|
|
110
|
-
headers: responseHeaders,
|
|
111
123
|
status,
|
|
112
124
|
statusText,
|
|
113
125
|
});
|
|
114
|
-
// url
|
|
126
|
+
// url and headers are read only properties
|
|
127
|
+
// but seems like we can set them like this
|
|
128
|
+
//
|
|
129
|
+
// we define theme like this, because using `Response`
|
|
130
|
+
// constructor, it removes url and some headers
|
|
131
|
+
// like `set-cookie` headers
|
|
115
132
|
Object.defineProperty(res, "url", { value: url });
|
|
133
|
+
Object.defineProperty(res, "headers", {
|
|
134
|
+
value: new Headers(responseHeaders),
|
|
135
|
+
});
|
|
116
136
|
return res;
|
|
117
137
|
}
|
|
118
138
|
|
package/dist-js/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { invoke } from '@tauri-apps/api/core';
|
|
|
26
26
|
*
|
|
27
27
|
* @module
|
|
28
28
|
*/
|
|
29
|
+
const ERROR_REQUEST_CANCELLED = "Request canceled";
|
|
29
30
|
/**
|
|
30
31
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
|
31
32
|
* `Response` to that `Request`, whether it is successful or not.
|
|
@@ -41,6 +42,11 @@ import { invoke } from '@tauri-apps/api/core';
|
|
|
41
42
|
* @since 2.0.0
|
|
42
43
|
*/
|
|
43
44
|
async function fetch(input, init) {
|
|
45
|
+
// abort early here if needed
|
|
46
|
+
const signal = init?.signal;
|
|
47
|
+
if (signal?.aborted) {
|
|
48
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
49
|
+
}
|
|
44
50
|
const maxRedirections = init?.maxRedirections;
|
|
45
51
|
const connectTimeout = init?.connectTimeout;
|
|
46
52
|
const proxy = init?.proxy;
|
|
@@ -50,7 +56,6 @@ async function fetch(input, init) {
|
|
|
50
56
|
delete init.connectTimeout;
|
|
51
57
|
delete init.proxy;
|
|
52
58
|
}
|
|
53
|
-
const signal = init?.signal;
|
|
54
59
|
const headers = init?.headers
|
|
55
60
|
? init.headers instanceof Headers
|
|
56
61
|
? init.headers
|
|
@@ -78,6 +83,10 @@ async function fetch(input, init) {
|
|
|
78
83
|
// eslint-disable-next-line
|
|
79
84
|
typeof val === "string" ? val : val.toString(),
|
|
80
85
|
]);
|
|
86
|
+
// abort early here if needed
|
|
87
|
+
if (signal?.aborted) {
|
|
88
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
89
|
+
}
|
|
81
90
|
const rid = await invoke("plugin:http|fetch", {
|
|
82
91
|
clientConfig: {
|
|
83
92
|
method: req.method,
|
|
@@ -89,11 +98,15 @@ async function fetch(input, init) {
|
|
|
89
98
|
proxy,
|
|
90
99
|
},
|
|
91
100
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
const abort = () => invoke("plugin:http|fetch_cancel", { rid });
|
|
102
|
+
// abort early here if needed
|
|
103
|
+
if (signal?.aborted) {
|
|
104
|
+
// we don't care about the result of this proimse
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
106
|
+
abort();
|
|
107
|
+
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
108
|
+
}
|
|
109
|
+
signal?.addEventListener("abort", () => abort);
|
|
97
110
|
const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await invoke("plugin:http|fetch_send", {
|
|
98
111
|
rid,
|
|
99
112
|
});
|
|
@@ -105,12 +118,19 @@ async function fetch(input, init) {
|
|
|
105
118
|
: body instanceof Array && body.length > 0
|
|
106
119
|
? new Uint8Array(body)
|
|
107
120
|
: null, {
|
|
108
|
-
headers: responseHeaders,
|
|
109
121
|
status,
|
|
110
122
|
statusText,
|
|
111
123
|
});
|
|
112
|
-
// url
|
|
124
|
+
// url and headers are read only properties
|
|
125
|
+
// but seems like we can set them like this
|
|
126
|
+
//
|
|
127
|
+
// we define theme like this, because using `Response`
|
|
128
|
+
// constructor, it removes url and some headers
|
|
129
|
+
// like `set-cookie` headers
|
|
113
130
|
Object.defineProperty(res, "url", { value: url });
|
|
131
|
+
Object.defineProperty(res, "headers", {
|
|
132
|
+
value: new Headers(responseHeaders),
|
|
133
|
+
});
|
|
114
134
|
return res;
|
|
115
135
|
}
|
|
116
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-http",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.8",
|
|
4
4
|
"license": "MIT or APACHE-2.0",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Tauri Programme within The Commons Conservancy"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tauri-apps/api": "2.0.0-beta.
|
|
23
|
+
"@tauri-apps/api": "2.0.0-beta.15"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c"
|