Skip to content

Commit 6cf36fb

Browse files
committed
fix: revert command back to fetch_read_body to comply with permissions
1 parent 1ec0de8 commit 6cf36fb

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

plugins/http/guest-js/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ export async function fetch(
186186
throw new Error(ERROR_REQUEST_CANCELLED)
187187
}
188188

189+
const rid = await invoke<number>('plugin:http|fetch', {
190+
clientConfig: {
191+
method: req.method,
192+
url: req.url,
193+
headers: mappedHeaders,
194+
data,
195+
maxRedirections,
196+
connectTimeout,
197+
proxy,
198+
danger
199+
}
200+
})
201+
189202
const readableStreamBody = new ReadableStream({
190203
start: (controller) => {
191204
const streamChannel = new Channel<ArrayBuffer | number[]>()
@@ -212,7 +225,7 @@ export async function fetch(
212225
}
213226

214227
// run a non-blocking body stream fetch
215-
invoke('plugin:http|fetch_stream_body', {
228+
invoke('plugin:http|fetch_read_body', {
216229
rid,
217230
streamChannel
218231
}).catch((e) => {
@@ -221,19 +234,6 @@ export async function fetch(
221234
}
222235
})
223236

224-
const rid = await invoke<number>('plugin:http|fetch', {
225-
clientConfig: {
226-
method: req.method,
227-
url: req.url,
228-
headers: mappedHeaders,
229-
data,
230-
maxRedirections,
231-
connectTimeout,
232-
proxy,
233-
danger
234-
}
235-
})
236-
237237
const abort = () => invoke('plugin:http|fetch_cancel', { rid })
238238

239239
// abort early here if needed

plugins/http/permissions/autogenerated/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ All fetch operations are enabled.
1515

1616
- `allow-fetch`
1717
- `allow-fetch-cancel`
18-
- `allow-fetch-read-body`
18+
- `allow-fetch-stream-body`
1919
- `allow-fetch-send`
2020

2121
## Permission Table

plugins/http/permissions/schemas/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@
314314
"type": "string",
315315
"const": "deny-fetch-cancel"
316316
},
317+
{
318+
"description": "Enables the fetch_read_body command without any pre-configured scope.",
319+
"type": "string",
320+
"const": "allow-fetch-read-body"
321+
},
322+
{
323+
"description": "Denies the fetch_read_body command without any pre-configured scope.",
324+
"type": "string",
325+
"const": "deny-fetch-read-body"
326+
},
317327
{
318328
"description": "Enables the fetch_send command without any pre-configured scope.",
319329
"type": "string",

plugins/http/src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn fetch_cancel<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> crate::
360360
}
361361

362362
#[command]
363-
pub async fn fetch_stream_body<R: Runtime>(
363+
pub async fn fetch_read_body<R: Runtime>(
364364
webview: Webview<R>,
365365
rid: ResourceId,
366366
stream_channel: Channel<tauri::ipc::InvokeResponseBody>,

plugins/http/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
3737
commands::fetch,
3838
commands::fetch_cancel,
3939
commands::fetch_send,
40-
commands::fetch_stream_body,
40+
commands::fetch_read_body,
4141
])
4242
.build()
4343
}

0 commit comments

Comments
 (0)