@tauri-apps/plugin-http 2.6.0 → 2.7.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 CHANGED
@@ -12,7 +12,7 @@ Access the HTTP client written in Rust.
12
12
 
13
13
  ## Install
14
14
 
15
- _This plugin requires a Rust version of at least **1.77.2**_
15
+ _This plugin requires a Rust version of at least **1.90**_
16
16
 
17
17
  There are three general methods of installation that we can recommend.
18
18
 
package/dist-js/index.cjs CHANGED
@@ -33,14 +33,24 @@ const ERROR_REQUEST_CANCELLED = 'Request cancelled';
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.
35
35
  *
36
+ * The request is performed by the Rust backend instead of the webview, so it is not subject to
37
+ * CORS, but the URL must be allowed by the plugin scope.
38
+ *
36
39
  * @example
37
40
  * ```typescript
41
+ * import { fetch } from '@tauri-apps/plugin-http';
38
42
  * const response = await fetch("http://my.json.host/data.json");
39
43
  * console.log(response.status); // e.g. 200
40
44
  * console.log(response.statusText); // e.g. "OK"
41
45
  * const jsonData = await response.json();
42
46
  * ```
43
47
  *
48
+ * @param input The resource to fetch, as a URL, a string or a `Request` object.
49
+ * @param init The standard `fetch` request options, extended with the Rust client options from
50
+ * {@linkcode ClientOptions}: `maxRedirections`, `connectTimeout`, `proxy` and `danger`. The
51
+ * `signal` option can be used to abort the request.
52
+ * @returns A promise resolving to the `Response` of the request.
53
+ *
44
54
  * @since 2.0.0
45
55
  */
46
56
  async function fetch(input, init) {
@@ -103,21 +113,24 @@ async function fetch(input, init) {
103
113
  danger
104
114
  }
105
115
  });
106
- const abort = () => core.invoke('plugin:http|fetch_cancel', { rid });
116
+ const abort = () => core.invoke('plugin:http|fetch_cancel', { rid }).catch(() => { });
107
117
  // Optimistically check for abort signal
108
118
  // and avoid doing any work after doing intial work on the Rust side
109
119
  if (signal?.aborted) {
110
- // we don't care about the result of this proimse
111
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
112
- abort();
120
+ // we don't care about the result of this promise
121
+ void abort();
113
122
  throw new Error(ERROR_REQUEST_CANCELLED);
114
123
  }
115
124
  signal?.addEventListener('abort', () => void abort());
116
125
  const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await core.invoke('plugin:http|fetch_send', {
117
126
  rid
118
127
  });
128
+ let bodyDropped = false;
119
129
  const dropBody = () => {
120
- return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
130
+ if (bodyDropped)
131
+ return Promise.resolve();
132
+ bodyDropped = true;
133
+ return core.invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => { });
121
134
  };
122
135
  const readChunk = async (controller) => {
123
136
  let data;
@@ -17,6 +17,11 @@ export interface Proxy {
17
17
  */
18
18
  https?: string | ProxyConfig;
19
19
  }
20
+ /**
21
+ * Detailed configuration of a single proxy server, used when a plain URL string is not enough.
22
+ *
23
+ * @since 2.0.0
24
+ */
20
25
  export interface ProxyConfig {
21
26
  /**
22
27
  * The URL of the proxy server.
@@ -26,7 +31,13 @@ export interface ProxyConfig {
26
31
  * Set the `Proxy-Authorization` header using Basic auth.
27
32
  */
28
33
  basicAuth?: {
34
+ /**
35
+ * The user name sent to the proxy server.
36
+ */
29
37
  username: string;
38
+ /**
39
+ * The password sent to the proxy server.
40
+ */
30
41
  password: string;
31
42
  };
32
43
  /**
@@ -44,6 +55,10 @@ export interface ClientOptions {
44
55
  /**
45
56
  * Defines the maximum number of redirects the client should follow.
46
57
  * If set to 0, no redirects will be followed.
58
+ *
59
+ * When the `scopeRedirects` plugin configuration is enabled, every redirect must
60
+ * also be allowed by the configured scope, otherwise the request fails
61
+ * instead of being followed.
47
62
  */
48
63
  maxRedirections?: number;
49
64
  /** Timeout in milliseconds */
@@ -76,14 +91,24 @@ export interface DangerousSettings {
76
91
  * Fetch a resource from the network. It returns a `Promise` that resolves to the
77
92
  * `Response` to that `Request`, whether it is successful or not.
78
93
  *
94
+ * The request is performed by the Rust backend instead of the webview, so it is not subject to
95
+ * CORS, but the URL must be allowed by the plugin scope.
96
+ *
79
97
  * @example
80
98
  * ```typescript
99
+ * import { fetch } from '@tauri-apps/plugin-http';
81
100
  * const response = await fetch("http://my.json.host/data.json");
82
101
  * console.log(response.status); // e.g. 200
83
102
  * console.log(response.statusText); // e.g. "OK"
84
103
  * const jsonData = await response.json();
85
104
  * ```
86
105
  *
106
+ * @param input The resource to fetch, as a URL, a string or a `Request` object.
107
+ * @param init The standard `fetch` request options, extended with the Rust client options from
108
+ * {@linkcode ClientOptions}: `maxRedirections`, `connectTimeout`, `proxy` and `danger`. The
109
+ * `signal` option can be used to abort the request.
110
+ * @returns A promise resolving to the `Response` of the request.
111
+ *
87
112
  * @since 2.0.0
88
113
  */
89
114
  export declare function fetch(input: URL | Request | string, init?: RequestInit & ClientOptions): Promise<Response>;
package/dist-js/index.js CHANGED
@@ -31,14 +31,24 @@ const ERROR_REQUEST_CANCELLED = 'Request cancelled';
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.
33
33
  *
34
+ * The request is performed by the Rust backend instead of the webview, so it is not subject to
35
+ * CORS, but the URL must be allowed by the plugin scope.
36
+ *
34
37
  * @example
35
38
  * ```typescript
39
+ * import { fetch } from '@tauri-apps/plugin-http';
36
40
  * const response = await fetch("http://my.json.host/data.json");
37
41
  * console.log(response.status); // e.g. 200
38
42
  * console.log(response.statusText); // e.g. "OK"
39
43
  * const jsonData = await response.json();
40
44
  * ```
41
45
  *
46
+ * @param input The resource to fetch, as a URL, a string or a `Request` object.
47
+ * @param init The standard `fetch` request options, extended with the Rust client options from
48
+ * {@linkcode ClientOptions}: `maxRedirections`, `connectTimeout`, `proxy` and `danger`. The
49
+ * `signal` option can be used to abort the request.
50
+ * @returns A promise resolving to the `Response` of the request.
51
+ *
42
52
  * @since 2.0.0
43
53
  */
44
54
  async function fetch(input, init) {
@@ -101,21 +111,24 @@ async function fetch(input, init) {
101
111
  danger
102
112
  }
103
113
  });
104
- const abort = () => invoke('plugin:http|fetch_cancel', { rid });
114
+ const abort = () => invoke('plugin:http|fetch_cancel', { rid }).catch(() => { });
105
115
  // Optimistically check for abort signal
106
116
  // and avoid doing any work after doing intial work on the Rust side
107
117
  if (signal?.aborted) {
108
- // we don't care about the result of this proimse
109
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
110
- abort();
118
+ // we don't care about the result of this promise
119
+ void abort();
111
120
  throw new Error(ERROR_REQUEST_CANCELLED);
112
121
  }
113
122
  signal?.addEventListener('abort', () => void abort());
114
123
  const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', {
115
124
  rid
116
125
  });
126
+ let bodyDropped = false;
117
127
  const dropBody = () => {
118
- return invoke('plugin:http|fetch_cancel_body', { rid: responseRid });
128
+ if (bodyDropped)
129
+ return Promise.resolve();
130
+ bodyDropped = true;
131
+ return invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(() => { });
119
132
  };
120
133
  const readChunk = async (controller) => {
121
134
  let data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
@@ -24,6 +24,6 @@
24
24
  "LICENSE"
25
25
  ],
26
26
  "dependencies": {
27
- "@tauri-apps/api": "^2.11.0"
27
+ "@tauri-apps/api": "^2.12.0"
28
28
  }
29
29
  }