@tauri-apps/plugin-http 2.0.0-beta.3 → 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 CHANGED
@@ -45,34 +45,44 @@ 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 != null) {
48
+ if (init) {
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]) => [
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 !== 0 ? 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: reqData,
85
+ data,
76
86
  maxRedirections,
77
87
  connectTimeout,
78
88
  proxy,
package/dist-js/index.js CHANGED
@@ -43,34 +43,44 @@ 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 != null) {
46
+ if (init) {
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]) => [
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 !== 0 ? 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: reqData,
83
+ data,
74
84
  maxRedirections,
75
85
  connectTimeout,
76
86
  proxy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.0.0-beta.3",
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.11"
23
+ "@tauri-apps/api": "2.0.0-beta.12"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "rollup -c"