@tauri-apps/plugin-http 2.2.0 → 2.4.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/dist-js/index.cjs +31 -11
- package/dist-js/index.d.ts +19 -0
- package/dist-js/index.js +32 -12
- package/package.json +1 -1
package/dist-js/index.cjs
CHANGED
|
@@ -52,11 +52,13 @@ async function fetch(input, init) {
|
|
|
52
52
|
const maxRedirections = init?.maxRedirections;
|
|
53
53
|
const connectTimeout = init?.connectTimeout;
|
|
54
54
|
const proxy = init?.proxy;
|
|
55
|
+
const danger = init?.danger;
|
|
55
56
|
// Remove these fields before creating the request
|
|
56
57
|
if (init) {
|
|
57
58
|
delete init.maxRedirections;
|
|
58
59
|
delete init.connectTimeout;
|
|
59
60
|
delete init.proxy;
|
|
61
|
+
delete init.danger;
|
|
60
62
|
}
|
|
61
63
|
const headers = init?.headers
|
|
62
64
|
? init.headers instanceof Headers
|
|
@@ -89,6 +91,29 @@ async function fetch(input, init) {
|
|
|
89
91
|
if (signal?.aborted) {
|
|
90
92
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
91
93
|
}
|
|
94
|
+
const streamChannel = new core.Channel();
|
|
95
|
+
const readableStreamBody = new ReadableStream({
|
|
96
|
+
start: (controller) => {
|
|
97
|
+
streamChannel.onmessage = (res) => {
|
|
98
|
+
// close early if aborted
|
|
99
|
+
if (signal?.aborted) {
|
|
100
|
+
controller.error(ERROR_REQUEST_CANCELLED);
|
|
101
|
+
controller.close();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// close when the signal to close (an empty chunk)
|
|
105
|
+
// is sent from the IPC.
|
|
106
|
+
if (res instanceof ArrayBuffer ? res.byteLength == 0 : res.length == 0) {
|
|
107
|
+
controller.close();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// the content conversion (like .text(), .json(), etc.) in Response
|
|
111
|
+
// must have Uint8Array as its content, else it will
|
|
112
|
+
// have untraceable error that's hard to debug.
|
|
113
|
+
controller.enqueue(new Uint8Array(res));
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
92
117
|
const rid = await core.invoke('plugin:http|fetch', {
|
|
93
118
|
clientConfig: {
|
|
94
119
|
method: req.method,
|
|
@@ -97,8 +122,10 @@ async function fetch(input, init) {
|
|
|
97
122
|
data,
|
|
98
123
|
maxRedirections,
|
|
99
124
|
connectTimeout,
|
|
100
|
-
proxy
|
|
101
|
-
|
|
125
|
+
proxy,
|
|
126
|
+
danger
|
|
127
|
+
},
|
|
128
|
+
streamChannel
|
|
102
129
|
});
|
|
103
130
|
const abort = () => core.invoke('plugin:http|fetch_cancel', { rid });
|
|
104
131
|
// abort early here if needed
|
|
@@ -109,17 +136,10 @@ async function fetch(input, init) {
|
|
|
109
136
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
110
137
|
}
|
|
111
138
|
signal?.addEventListener('abort', () => void abort());
|
|
112
|
-
const { status, statusText, url, headers: responseHeaders
|
|
139
|
+
const { status, statusText, url, headers: responseHeaders } = await core.invoke('plugin:http|fetch_send', {
|
|
113
140
|
rid
|
|
114
141
|
});
|
|
115
|
-
const
|
|
116
|
-
rid: responseRid
|
|
117
|
-
});
|
|
118
|
-
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
119
|
-
? body
|
|
120
|
-
: body instanceof Array && body.length > 0
|
|
121
|
-
? new Uint8Array(body)
|
|
122
|
-
: null, {
|
|
142
|
+
const res = new Response(readableStreamBody, {
|
|
123
143
|
status,
|
|
124
144
|
statusText
|
|
125
145
|
});
|
package/dist-js/index.d.ts
CHANGED
|
@@ -52,6 +52,25 @@ export interface ClientOptions {
|
|
|
52
52
|
* Configuration of a proxy that a Client should pass requests to.
|
|
53
53
|
*/
|
|
54
54
|
proxy?: Proxy;
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for dangerous settings on the client such as disabling SSL verification.
|
|
57
|
+
*/
|
|
58
|
+
danger?: DangerousSettings;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for dangerous settings on the client such as disabling SSL verification.
|
|
62
|
+
*
|
|
63
|
+
* @since 2.3.0
|
|
64
|
+
*/
|
|
65
|
+
export interface DangerousSettings {
|
|
66
|
+
/**
|
|
67
|
+
* Disables SSL verification.
|
|
68
|
+
*/
|
|
69
|
+
acceptInvalidCerts?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Disables hostname verification.
|
|
72
|
+
*/
|
|
73
|
+
acceptInvalidHostnames?: boolean;
|
|
55
74
|
}
|
|
56
75
|
/**
|
|
57
76
|
* Fetch a resource from the network. It returns a `Promise` that resolves to the
|
package/dist-js/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { invoke } from '@tauri-apps/api/core';
|
|
1
|
+
import { Channel, invoke } from '@tauri-apps/api/core';
|
|
2
2
|
|
|
3
3
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -50,11 +50,13 @@ async function fetch(input, init) {
|
|
|
50
50
|
const maxRedirections = init?.maxRedirections;
|
|
51
51
|
const connectTimeout = init?.connectTimeout;
|
|
52
52
|
const proxy = init?.proxy;
|
|
53
|
+
const danger = init?.danger;
|
|
53
54
|
// Remove these fields before creating the request
|
|
54
55
|
if (init) {
|
|
55
56
|
delete init.maxRedirections;
|
|
56
57
|
delete init.connectTimeout;
|
|
57
58
|
delete init.proxy;
|
|
59
|
+
delete init.danger;
|
|
58
60
|
}
|
|
59
61
|
const headers = init?.headers
|
|
60
62
|
? init.headers instanceof Headers
|
|
@@ -87,6 +89,29 @@ async function fetch(input, init) {
|
|
|
87
89
|
if (signal?.aborted) {
|
|
88
90
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
89
91
|
}
|
|
92
|
+
const streamChannel = new Channel();
|
|
93
|
+
const readableStreamBody = new ReadableStream({
|
|
94
|
+
start: (controller) => {
|
|
95
|
+
streamChannel.onmessage = (res) => {
|
|
96
|
+
// close early if aborted
|
|
97
|
+
if (signal?.aborted) {
|
|
98
|
+
controller.error(ERROR_REQUEST_CANCELLED);
|
|
99
|
+
controller.close();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// close when the signal to close (an empty chunk)
|
|
103
|
+
// is sent from the IPC.
|
|
104
|
+
if (res instanceof ArrayBuffer ? res.byteLength == 0 : res.length == 0) {
|
|
105
|
+
controller.close();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// the content conversion (like .text(), .json(), etc.) in Response
|
|
109
|
+
// must have Uint8Array as its content, else it will
|
|
110
|
+
// have untraceable error that's hard to debug.
|
|
111
|
+
controller.enqueue(new Uint8Array(res));
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
90
115
|
const rid = await invoke('plugin:http|fetch', {
|
|
91
116
|
clientConfig: {
|
|
92
117
|
method: req.method,
|
|
@@ -95,8 +120,10 @@ async function fetch(input, init) {
|
|
|
95
120
|
data,
|
|
96
121
|
maxRedirections,
|
|
97
122
|
connectTimeout,
|
|
98
|
-
proxy
|
|
99
|
-
|
|
123
|
+
proxy,
|
|
124
|
+
danger
|
|
125
|
+
},
|
|
126
|
+
streamChannel
|
|
100
127
|
});
|
|
101
128
|
const abort = () => invoke('plugin:http|fetch_cancel', { rid });
|
|
102
129
|
// abort early here if needed
|
|
@@ -107,17 +134,10 @@ async function fetch(input, init) {
|
|
|
107
134
|
throw new Error(ERROR_REQUEST_CANCELLED);
|
|
108
135
|
}
|
|
109
136
|
signal?.addEventListener('abort', () => void abort());
|
|
110
|
-
const { status, statusText, url, headers: responseHeaders
|
|
137
|
+
const { status, statusText, url, headers: responseHeaders } = await invoke('plugin:http|fetch_send', {
|
|
111
138
|
rid
|
|
112
139
|
});
|
|
113
|
-
const
|
|
114
|
-
rid: responseRid
|
|
115
|
-
});
|
|
116
|
-
const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0
|
|
117
|
-
? body
|
|
118
|
-
: body instanceof Array && body.length > 0
|
|
119
|
-
? new Uint8Array(body)
|
|
120
|
-
: null, {
|
|
140
|
+
const res = new Response(readableStreamBody, {
|
|
121
141
|
status,
|
|
122
142
|
statusText
|
|
123
143
|
});
|