@tauri-apps/plugin-http 2.0.0-beta.1 → 2.0.0-beta.3

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 CHANGED
@@ -45,20 +45,33 @@ async function fetch(input, init) {
45
45
  const connectTimeout = init?.connectTimeout;
46
46
  const proxy = init?.proxy;
47
47
  // Remove these fields before creating the request
48
- if (init) {
48
+ if (init != null) {
49
49
  delete init.maxRedirections;
50
50
  delete init.connectTimeout;
51
51
  delete init.proxy;
52
52
  }
53
53
  const signal = init?.signal;
54
+ const headers = init?.headers == null
55
+ ? []
56
+ : init.headers instanceof Headers
57
+ ? Array.from(init.headers.entries())
58
+ : Array.isArray(init.headers)
59
+ ? init.headers
60
+ : Object.entries(init.headers);
61
+ const mappedHeaders = headers.map(([name, val]) => [
62
+ name,
63
+ // we need to ensure we have all values as strings
64
+ // eslint-disable-next-line
65
+ typeof val === "string" ? val : val.toString(),
66
+ ]);
54
67
  const req = new Request(input, init);
55
68
  const buffer = await req.arrayBuffer();
56
- const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
69
+ const reqData = buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null;
57
70
  const rid = await core.invoke("plugin:http|fetch", {
58
71
  clientConfig: {
59
72
  method: req.method,
60
73
  url: req.url,
61
- headers: Array.from(req.headers.entries()),
74
+ headers: mappedHeaders,
62
75
  data: reqData,
63
76
  maxRedirections,
64
77
  connectTimeout,
@@ -66,22 +79,22 @@ async function fetch(input, init) {
66
79
  },
67
80
  });
68
81
  signal?.addEventListener("abort", () => {
69
- core.invoke("plugin:http|fetch_cancel", {
82
+ void core.invoke("plugin:http|fetch_cancel", {
70
83
  rid,
71
84
  });
72
85
  });
73
- const { status, statusText, url, headers, rid: responseRid, } = await core.invoke("plugin:http|fetch_send", {
86
+ const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await core.invoke("plugin:http|fetch_send", {
74
87
  rid,
75
88
  });
76
89
  const body = await core.invoke("plugin:http|fetch_read_body", {
77
90
  rid: responseRid,
78
91
  });
79
- const res = new Response(body instanceof ArrayBuffer && body.byteLength
92
+ const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
80
93
  ? body
81
- : body instanceof Array && body.length
94
+ : body instanceof Array && body.length > 0
82
95
  ? new Uint8Array(body)
83
96
  : null, {
84
- headers,
97
+ headers: responseHeaders,
85
98
  status,
86
99
  statusText,
87
100
  });
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @since 2.0.0
5
5
  */
6
- export type Proxy = {
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’t be proxied.
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
@@ -43,20 +43,33 @@ async function fetch(input, init) {
43
43
  const connectTimeout = init?.connectTimeout;
44
44
  const proxy = init?.proxy;
45
45
  // Remove these fields before creating the request
46
- if (init) {
46
+ if (init != null) {
47
47
  delete init.maxRedirections;
48
48
  delete init.connectTimeout;
49
49
  delete init.proxy;
50
50
  }
51
51
  const signal = init?.signal;
52
+ const headers = init?.headers == null
53
+ ? []
54
+ : init.headers instanceof Headers
55
+ ? Array.from(init.headers.entries())
56
+ : Array.isArray(init.headers)
57
+ ? init.headers
58
+ : Object.entries(init.headers);
59
+ const mappedHeaders = headers.map(([name, val]) => [
60
+ name,
61
+ // we need to ensure we have all values as strings
62
+ // eslint-disable-next-line
63
+ typeof val === "string" ? val : val.toString(),
64
+ ]);
52
65
  const req = new Request(input, init);
53
66
  const buffer = await req.arrayBuffer();
54
- const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
67
+ const reqData = buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null;
55
68
  const rid = await invoke("plugin:http|fetch", {
56
69
  clientConfig: {
57
70
  method: req.method,
58
71
  url: req.url,
59
- headers: Array.from(req.headers.entries()),
72
+ headers: mappedHeaders,
60
73
  data: reqData,
61
74
  maxRedirections,
62
75
  connectTimeout,
@@ -64,22 +77,22 @@ async function fetch(input, init) {
64
77
  },
65
78
  });
66
79
  signal?.addEventListener("abort", () => {
67
- invoke("plugin:http|fetch_cancel", {
80
+ void invoke("plugin:http|fetch_cancel", {
68
81
  rid,
69
82
  });
70
83
  });
71
- const { status, statusText, url, headers, rid: responseRid, } = await invoke("plugin:http|fetch_send", {
84
+ const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await invoke("plugin:http|fetch_send", {
72
85
  rid,
73
86
  });
74
87
  const body = await invoke("plugin:http|fetch_read_body", {
75
88
  rid: responseRid,
76
89
  });
77
- const res = new Response(body instanceof ArrayBuffer && body.byteLength
90
+ const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
78
91
  ? body
79
- : body instanceof Array && body.length
92
+ : body instanceof Array && body.length > 0
80
93
  ? new Uint8Array(body)
81
94
  : null, {
82
- headers,
95
+ headers: responseHeaders,
83
96
  status,
84
97
  statusText,
85
98
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
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.2"
23
+ "@tauri-apps/api": "2.0.0-beta.11"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "rollup -c"