@tauri-apps/plugin-http 2.0.0-alpha.5 → 2.0.0-alpha.6
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 +11 -6
- package/dist-js/index.d.ts +41 -0
- package/dist-js/index.js +11 -6
- package/package.json +1 -1
package/dist-js/index.cjs
CHANGED
|
@@ -43,21 +43,26 @@ var core = require('@tauri-apps/api/core');
|
|
|
43
43
|
async function fetch(input, init) {
|
|
44
44
|
const maxRedirections = init?.maxRedirections;
|
|
45
45
|
const connectTimeout = init?.maxRedirections;
|
|
46
|
+
const proxy = init?.proxy;
|
|
46
47
|
// Remove these fields before creating the request
|
|
47
48
|
if (init) {
|
|
48
49
|
delete init.maxRedirections;
|
|
49
50
|
delete init.connectTimeout;
|
|
51
|
+
delete init.proxy;
|
|
50
52
|
}
|
|
51
53
|
const req = new Request(input, init);
|
|
52
54
|
const buffer = await req.arrayBuffer();
|
|
53
55
|
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
|
54
56
|
const rid = await core.invoke("plugin:http|fetch", {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
clientConfig: {
|
|
58
|
+
method: req.method,
|
|
59
|
+
url: req.url,
|
|
60
|
+
headers: Array.from(req.headers.entries()),
|
|
61
|
+
data: reqData,
|
|
62
|
+
maxRedirections,
|
|
63
|
+
connectTimeout,
|
|
64
|
+
proxy,
|
|
65
|
+
},
|
|
61
66
|
});
|
|
62
67
|
req.signal.addEventListener("abort", () => {
|
|
63
68
|
core.invoke("plugin:http|fetch_cancel", {
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration of a proxy that a Client should pass requests to.
|
|
3
|
+
*
|
|
4
|
+
* @since 2.0.0
|
|
5
|
+
*/
|
|
6
|
+
export type Proxy = {
|
|
7
|
+
/**
|
|
8
|
+
* Proxy all traffic to the passed URL.
|
|
9
|
+
*/
|
|
10
|
+
all?: string | ProxyConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Proxy all HTTP traffic to the passed URL.
|
|
13
|
+
*/
|
|
14
|
+
http?: string | ProxyConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Proxy all HTTPS traffic to the passed URL.
|
|
17
|
+
*/
|
|
18
|
+
https?: string | ProxyConfig;
|
|
19
|
+
};
|
|
20
|
+
export interface ProxyConfig {
|
|
21
|
+
/**
|
|
22
|
+
* The URL of the proxy server.
|
|
23
|
+
*/
|
|
24
|
+
url: string;
|
|
25
|
+
/**
|
|
26
|
+
* Set the `Proxy-Authorization` header using Basic auth.
|
|
27
|
+
*/
|
|
28
|
+
basicAuth?: {
|
|
29
|
+
username: string;
|
|
30
|
+
password: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A configuration for filtering out requests that shouldn’t be proxied.
|
|
34
|
+
* Entries are expected to be comma-separated (whitespace between entries is ignored)
|
|
35
|
+
*/
|
|
36
|
+
noProxy?: string;
|
|
37
|
+
}
|
|
1
38
|
/**
|
|
2
39
|
* Options to configure the Rust client used to make fetch requests
|
|
3
40
|
*
|
|
@@ -11,6 +48,10 @@ export interface ClientOptions {
|
|
|
11
48
|
maxRedirections?: number;
|
|
12
49
|
/** Timeout in milliseconds */
|
|
13
50
|
connectTimeout?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Configuration of a proxy that a Client should pass requests to.
|
|
53
|
+
*/
|
|
54
|
+
proxy?: Proxy;
|
|
14
55
|
}
|
|
15
56
|
/**
|
|
16
57
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
package/dist-js/index.js
CHANGED
|
@@ -41,21 +41,26 @@ import { invoke } from '@tauri-apps/api/core';
|
|
|
41
41
|
async function fetch(input, init) {
|
|
42
42
|
const maxRedirections = init?.maxRedirections;
|
|
43
43
|
const connectTimeout = init?.maxRedirections;
|
|
44
|
+
const proxy = init?.proxy;
|
|
44
45
|
// Remove these fields before creating the request
|
|
45
46
|
if (init) {
|
|
46
47
|
delete init.maxRedirections;
|
|
47
48
|
delete init.connectTimeout;
|
|
49
|
+
delete init.proxy;
|
|
48
50
|
}
|
|
49
51
|
const req = new Request(input, init);
|
|
50
52
|
const buffer = await req.arrayBuffer();
|
|
51
53
|
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
|
52
54
|
const rid = await invoke("plugin:http|fetch", {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
clientConfig: {
|
|
56
|
+
method: req.method,
|
|
57
|
+
url: req.url,
|
|
58
|
+
headers: Array.from(req.headers.entries()),
|
|
59
|
+
data: reqData,
|
|
60
|
+
maxRedirections,
|
|
61
|
+
connectTimeout,
|
|
62
|
+
proxy,
|
|
63
|
+
},
|
|
59
64
|
});
|
|
60
65
|
req.signal.addEventListener("abort", () => {
|
|
61
66
|
invoke("plugin:http|fetch_cancel", {
|