@tauri-apps/plugin-http 2.0.0-beta.2 → 2.0.0-beta.4
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 +26 -16
- package/dist-js/index.d.ts +3 -3
- package/dist-js/index.js +26 -16
- package/package.json +2 -2
package/dist-js/index.cjs
CHANGED
|
@@ -51,35 +51,45 @@ async function fetch(input, init) {
|
|
|
51
51
|
delete init.proxy;
|
|
52
52
|
}
|
|
53
53
|
const signal = init?.signal;
|
|
54
|
-
const headers =
|
|
55
|
-
?
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
54
|
+
const headers = init?.headers
|
|
55
|
+
? init.headers instanceof Headers
|
|
56
|
+
? init.headers
|
|
57
|
+
: new Headers(init.headers)
|
|
58
|
+
: new Headers();
|
|
59
|
+
const req = new Request(input, init);
|
|
60
|
+
const buffer = await req.arrayBuffer();
|
|
61
|
+
const data = buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null;
|
|
62
|
+
// append new headers created by the browser `Request` implementation,
|
|
63
|
+
// if not already declared by the caller of this function
|
|
64
|
+
for (const [key, value] of req.headers) {
|
|
65
|
+
if (!headers.get(key)) {
|
|
66
|
+
headers.set(key, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const headersArray = headers instanceof Headers
|
|
70
|
+
? Array.from(headers.entries())
|
|
71
|
+
: Array.isArray(headers)
|
|
72
|
+
? headers
|
|
73
|
+
: Object.entries(headers);
|
|
74
|
+
const mappedHeaders = headersArray.map(([name, val]) => [
|
|
62
75
|
name,
|
|
63
|
-
// we need to ensure we have all values as strings
|
|
76
|
+
// we need to ensure we have all header values as strings
|
|
64
77
|
// eslint-disable-next-line
|
|
65
78
|
typeof val === "string" ? val : val.toString(),
|
|
66
79
|
]);
|
|
67
|
-
const req = new Request(input, init);
|
|
68
|
-
const buffer = await req.arrayBuffer();
|
|
69
|
-
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
|
70
80
|
const rid = await core.invoke("plugin:http|fetch", {
|
|
71
81
|
clientConfig: {
|
|
72
82
|
method: req.method,
|
|
73
83
|
url: req.url,
|
|
74
84
|
headers: mappedHeaders,
|
|
75
|
-
data
|
|
85
|
+
data,
|
|
76
86
|
maxRedirections,
|
|
77
87
|
connectTimeout,
|
|
78
88
|
proxy,
|
|
79
89
|
},
|
|
80
90
|
});
|
|
81
91
|
signal?.addEventListener("abort", () => {
|
|
82
|
-
core.invoke("plugin:http|fetch_cancel", {
|
|
92
|
+
void core.invoke("plugin:http|fetch_cancel", {
|
|
83
93
|
rid,
|
|
84
94
|
});
|
|
85
95
|
});
|
|
@@ -89,9 +99,9 @@ async function fetch(input, init) {
|
|
|
89
99
|
const body = await core.invoke("plugin:http|fetch_read_body", {
|
|
90
100
|
rid: responseRid,
|
|
91
101
|
});
|
|
92
|
-
const res = new Response(body instanceof ArrayBuffer && body.byteLength
|
|
102
|
+
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
93
103
|
? body
|
|
94
|
-
: body instanceof Array && body.length
|
|
104
|
+
: body instanceof Array && body.length > 0
|
|
95
105
|
? new Uint8Array(body)
|
|
96
106
|
: null, {
|
|
97
107
|
headers: responseHeaders,
|
package/dist-js/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @since 2.0.0
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export interface Proxy {
|
|
7
7
|
/**
|
|
8
8
|
* Proxy all traffic to the passed URL.
|
|
9
9
|
*/
|
|
@@ -16,7 +16,7 @@ export type Proxy = {
|
|
|
16
16
|
* Proxy all HTTPS traffic to the passed URL.
|
|
17
17
|
*/
|
|
18
18
|
https?: string | ProxyConfig;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
export interface ProxyConfig {
|
|
21
21
|
/**
|
|
22
22
|
* The URL of the proxy server.
|
|
@@ -30,7 +30,7 @@ export interface ProxyConfig {
|
|
|
30
30
|
password: string;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
* A configuration for filtering out requests that shouldn
|
|
33
|
+
* A configuration for filtering out requests that shouldn't be proxied.
|
|
34
34
|
* Entries are expected to be comma-separated (whitespace between entries is ignored)
|
|
35
35
|
*/
|
|
36
36
|
noProxy?: string;
|
package/dist-js/index.js
CHANGED
|
@@ -49,35 +49,45 @@ async function fetch(input, init) {
|
|
|
49
49
|
delete init.proxy;
|
|
50
50
|
}
|
|
51
51
|
const signal = init?.signal;
|
|
52
|
-
const headers =
|
|
53
|
-
?
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
52
|
+
const headers = init?.headers
|
|
53
|
+
? init.headers instanceof Headers
|
|
54
|
+
? init.headers
|
|
55
|
+
: new Headers(init.headers)
|
|
56
|
+
: new Headers();
|
|
57
|
+
const req = new Request(input, init);
|
|
58
|
+
const buffer = await req.arrayBuffer();
|
|
59
|
+
const data = buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null;
|
|
60
|
+
// append new headers created by the browser `Request` implementation,
|
|
61
|
+
// if not already declared by the caller of this function
|
|
62
|
+
for (const [key, value] of req.headers) {
|
|
63
|
+
if (!headers.get(key)) {
|
|
64
|
+
headers.set(key, value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const headersArray = headers instanceof Headers
|
|
68
|
+
? Array.from(headers.entries())
|
|
69
|
+
: Array.isArray(headers)
|
|
70
|
+
? headers
|
|
71
|
+
: Object.entries(headers);
|
|
72
|
+
const mappedHeaders = headersArray.map(([name, val]) => [
|
|
60
73
|
name,
|
|
61
|
-
// we need to ensure we have all values as strings
|
|
74
|
+
// we need to ensure we have all header values as strings
|
|
62
75
|
// eslint-disable-next-line
|
|
63
76
|
typeof val === "string" ? val : val.toString(),
|
|
64
77
|
]);
|
|
65
|
-
const req = new Request(input, init);
|
|
66
|
-
const buffer = await req.arrayBuffer();
|
|
67
|
-
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
|
|
68
78
|
const rid = await invoke("plugin:http|fetch", {
|
|
69
79
|
clientConfig: {
|
|
70
80
|
method: req.method,
|
|
71
81
|
url: req.url,
|
|
72
82
|
headers: mappedHeaders,
|
|
73
|
-
data
|
|
83
|
+
data,
|
|
74
84
|
maxRedirections,
|
|
75
85
|
connectTimeout,
|
|
76
86
|
proxy,
|
|
77
87
|
},
|
|
78
88
|
});
|
|
79
89
|
signal?.addEventListener("abort", () => {
|
|
80
|
-
invoke("plugin:http|fetch_cancel", {
|
|
90
|
+
void invoke("plugin:http|fetch_cancel", {
|
|
81
91
|
rid,
|
|
82
92
|
});
|
|
83
93
|
});
|
|
@@ -87,9 +97,9 @@ async function fetch(input, init) {
|
|
|
87
97
|
const body = await invoke("plugin:http|fetch_read_body", {
|
|
88
98
|
rid: responseRid,
|
|
89
99
|
});
|
|
90
|
-
const res = new Response(body instanceof ArrayBuffer && body.byteLength
|
|
100
|
+
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
91
101
|
? body
|
|
92
|
-
: body instanceof Array && body.length
|
|
102
|
+
: body instanceof Array && body.length > 0
|
|
93
103
|
? new Uint8Array(body)
|
|
94
104
|
: null, {
|
|
95
105
|
headers: responseHeaders,
|
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.4",
|
|
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.12"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c"
|