@tauri-apps/plugin-http 2.0.0-rc.1 → 2.0.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/README.md +15 -7
- package/dist-js/index.cjs +15 -15
- package/dist-js/index.js +15 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Access the HTTP client written in Rust.
|
|
4
4
|
|
|
5
|
+
| Platform | Supported |
|
|
6
|
+
| -------- | --------- |
|
|
7
|
+
| Linux | ✓ |
|
|
8
|
+
| Windows | ✓ |
|
|
9
|
+
| macOS | ✓ |
|
|
10
|
+
| Android | ✓ |
|
|
11
|
+
| iOS | ✓ |
|
|
12
|
+
|
|
5
13
|
## Install
|
|
6
14
|
|
|
7
|
-
_This plugin requires a Rust version of at least **1.
|
|
15
|
+
_This plugin requires a Rust version of at least **1.78**_
|
|
8
16
|
|
|
9
17
|
There are three general methods of installation that we can recommend.
|
|
10
18
|
|
|
@@ -18,7 +26,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
|
18
26
|
|
|
19
27
|
```toml
|
|
20
28
|
[dependencies]
|
|
21
|
-
tauri-plugin-http = "2.0.0
|
|
29
|
+
tauri-plugin-http = "2.0.0"
|
|
22
30
|
# alternatively with Git:
|
|
23
31
|
tauri-plugin-http = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
|
24
32
|
```
|
|
@@ -60,11 +68,11 @@ fn main() {
|
|
|
60
68
|
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
61
69
|
|
|
62
70
|
```javascript
|
|
63
|
-
import { fetch } from
|
|
64
|
-
const response = await fetch(
|
|
65
|
-
method:
|
|
66
|
-
timeout: 30
|
|
67
|
-
})
|
|
71
|
+
import { fetch } from '@tauri-apps/plugin-http'
|
|
72
|
+
const response = await fetch('http://localhost:3003/users/2', {
|
|
73
|
+
method: 'GET',
|
|
74
|
+
timeout: 30
|
|
75
|
+
})
|
|
68
76
|
```
|
|
69
77
|
|
|
70
78
|
## Contributing
|
package/dist-js/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ var core = require('@tauri-apps/api/core');
|
|
|
28
28
|
*
|
|
29
29
|
* @module
|
|
30
30
|
*/
|
|
31
|
-
const ERROR_REQUEST_CANCELLED =
|
|
31
|
+
const ERROR_REQUEST_CANCELLED = 'Request canceled';
|
|
32
32
|
/**
|
|
33
33
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
|
34
34
|
* `Response` to that `Request`, whether it is successful or not.
|
|
@@ -83,13 +83,13 @@ async function fetch(input, init) {
|
|
|
83
83
|
name,
|
|
84
84
|
// we need to ensure we have all header values as strings
|
|
85
85
|
// eslint-disable-next-line
|
|
86
|
-
typeof val ===
|
|
86
|
+
typeof val === 'string' ? val : val.toString()
|
|
87
87
|
]);
|
|
88
88
|
// abort early here if needed
|
|
89
89
|
if (signal?.aborted) {
|
|
90
90
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
91
91
|
}
|
|
92
|
-
const rid = await core.invoke(
|
|
92
|
+
const rid = await core.invoke('plugin:http|fetch', {
|
|
93
93
|
clientConfig: {
|
|
94
94
|
method: req.method,
|
|
95
95
|
url: req.url,
|
|
@@ -97,10 +97,10 @@ async function fetch(input, init) {
|
|
|
97
97
|
data,
|
|
98
98
|
maxRedirections,
|
|
99
99
|
connectTimeout,
|
|
100
|
-
proxy
|
|
101
|
-
}
|
|
100
|
+
proxy
|
|
101
|
+
}
|
|
102
102
|
});
|
|
103
|
-
const abort = () => core.invoke(
|
|
103
|
+
const abort = () => core.invoke('plugin:http|fetch_cancel', { rid });
|
|
104
104
|
// abort early here if needed
|
|
105
105
|
if (signal?.aborted) {
|
|
106
106
|
// we don't care about the result of this proimse
|
|
@@ -108,12 +108,12 @@ async function fetch(input, init) {
|
|
|
108
108
|
abort();
|
|
109
109
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
110
110
|
}
|
|
111
|
-
signal?.addEventListener(
|
|
112
|
-
const { status, statusText, url, headers: responseHeaders, rid: responseRid
|
|
113
|
-
rid
|
|
111
|
+
signal?.addEventListener('abort', () => void abort());
|
|
112
|
+
const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await core.invoke('plugin:http|fetch_send', {
|
|
113
|
+
rid
|
|
114
114
|
});
|
|
115
|
-
const body = await core.invoke(
|
|
116
|
-
rid: responseRid
|
|
115
|
+
const body = await core.invoke('plugin:http|fetch_read_body', {
|
|
116
|
+
rid: responseRid
|
|
117
117
|
});
|
|
118
118
|
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
119
119
|
? body
|
|
@@ -121,7 +121,7 @@ async function fetch(input, init) {
|
|
|
121
121
|
? new Uint8Array(body)
|
|
122
122
|
: null, {
|
|
123
123
|
status,
|
|
124
|
-
statusText
|
|
124
|
+
statusText
|
|
125
125
|
});
|
|
126
126
|
// url and headers are read only properties
|
|
127
127
|
// but seems like we can set them like this
|
|
@@ -129,9 +129,9 @@ async function fetch(input, init) {
|
|
|
129
129
|
// we define theme like this, because using `Response`
|
|
130
130
|
// constructor, it removes url and some headers
|
|
131
131
|
// like `set-cookie` headers
|
|
132
|
-
Object.defineProperty(res,
|
|
133
|
-
Object.defineProperty(res,
|
|
134
|
-
value: new Headers(responseHeaders)
|
|
132
|
+
Object.defineProperty(res, 'url', { value: url });
|
|
133
|
+
Object.defineProperty(res, 'headers', {
|
|
134
|
+
value: new Headers(responseHeaders)
|
|
135
135
|
});
|
|
136
136
|
return res;
|
|
137
137
|
}
|
package/dist-js/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import { invoke } from '@tauri-apps/api/core';
|
|
|
26
26
|
*
|
|
27
27
|
* @module
|
|
28
28
|
*/
|
|
29
|
-
const ERROR_REQUEST_CANCELLED =
|
|
29
|
+
const ERROR_REQUEST_CANCELLED = 'Request canceled';
|
|
30
30
|
/**
|
|
31
31
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
|
32
32
|
* `Response` to that `Request`, whether it is successful or not.
|
|
@@ -81,13 +81,13 @@ async function fetch(input, init) {
|
|
|
81
81
|
name,
|
|
82
82
|
// we need to ensure we have all header values as strings
|
|
83
83
|
// eslint-disable-next-line
|
|
84
|
-
typeof val ===
|
|
84
|
+
typeof val === 'string' ? val : val.toString()
|
|
85
85
|
]);
|
|
86
86
|
// abort early here if needed
|
|
87
87
|
if (signal?.aborted) {
|
|
88
88
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
89
89
|
}
|
|
90
|
-
const rid = await invoke(
|
|
90
|
+
const rid = await invoke('plugin:http|fetch', {
|
|
91
91
|
clientConfig: {
|
|
92
92
|
method: req.method,
|
|
93
93
|
url: req.url,
|
|
@@ -95,10 +95,10 @@ async function fetch(input, init) {
|
|
|
95
95
|
data,
|
|
96
96
|
maxRedirections,
|
|
97
97
|
connectTimeout,
|
|
98
|
-
proxy
|
|
99
|
-
}
|
|
98
|
+
proxy
|
|
99
|
+
}
|
|
100
100
|
});
|
|
101
|
-
const abort = () => invoke(
|
|
101
|
+
const abort = () => invoke('plugin:http|fetch_cancel', { rid });
|
|
102
102
|
// abort early here if needed
|
|
103
103
|
if (signal?.aborted) {
|
|
104
104
|
// we don't care about the result of this proimse
|
|
@@ -106,12 +106,12 @@ async function fetch(input, init) {
|
|
|
106
106
|
abort();
|
|
107
107
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
108
108
|
}
|
|
109
|
-
signal?.addEventListener(
|
|
110
|
-
const { status, statusText, url, headers: responseHeaders, rid: responseRid
|
|
111
|
-
rid
|
|
109
|
+
signal?.addEventListener('abort', () => void abort());
|
|
110
|
+
const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', {
|
|
111
|
+
rid
|
|
112
112
|
});
|
|
113
|
-
const body = await invoke(
|
|
114
|
-
rid: responseRid
|
|
113
|
+
const body = await invoke('plugin:http|fetch_read_body', {
|
|
114
|
+
rid: responseRid
|
|
115
115
|
});
|
|
116
116
|
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
117
117
|
? body
|
|
@@ -119,7 +119,7 @@ async function fetch(input, init) {
|
|
|
119
119
|
? new Uint8Array(body)
|
|
120
120
|
: null, {
|
|
121
121
|
status,
|
|
122
|
-
statusText
|
|
122
|
+
statusText
|
|
123
123
|
});
|
|
124
124
|
// url and headers are read only properties
|
|
125
125
|
// but seems like we can set them like this
|
|
@@ -127,9 +127,9 @@ async function fetch(input, init) {
|
|
|
127
127
|
// we define theme like this, because using `Response`
|
|
128
128
|
// constructor, it removes url and some headers
|
|
129
129
|
// like `set-cookie` headers
|
|
130
|
-
Object.defineProperty(res,
|
|
131
|
-
Object.defineProperty(res,
|
|
132
|
-
value: new Headers(responseHeaders)
|
|
130
|
+
Object.defineProperty(res, 'url', { value: url });
|
|
131
|
+
Object.defineProperty(res, 'headers', {
|
|
132
|
+
value: new Headers(responseHeaders)
|
|
133
133
|
});
|
|
134
134
|
return res;
|
|
135
135
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-http",
|
|
3
|
-
"version": "2.0.0
|
|
4
|
-
"license": "MIT
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"license": "MIT OR Apache-2.0",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Tauri Programme within The Commons Conservancy"
|
|
7
7
|
],
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tauri-apps/api": "^2.0.0
|
|
27
|
+
"@tauri-apps/api": "^2.0.0"
|
|
28
28
|
}
|
|
29
29
|
}
|