Skip to content

Commit bb66d44

Browse files
committed
fix: add fetch_read_body to lib.rs
1 parent ea012c1 commit bb66d44

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

plugins/http/src/commands.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -359,30 +359,6 @@ pub fn fetch_cancel<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> crate::
359359
Ok(())
360360
}
361361

362-
#[command]
363-
pub async fn fetch_read_body<R: Runtime>(
364-
webview: Webview<R>,
365-
rid: ResourceId,
366-
stream_channel: Channel<tauri::ipc::InvokeResponseBody>,
367-
) -> crate::Result<()> {
368-
let res = {
369-
let mut resources_table = webview.resources_table();
370-
resources_table.take::<ReqwestResponse>(rid)?
371-
};
372-
373-
let mut res = Arc::into_inner(res).unwrap().0;
374-
375-
// send response through IPC channel
376-
while let Some(chunk) = res.chunk().await? {
377-
stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?;
378-
}
379-
380-
// send empty vector when done
381-
stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?;
382-
383-
Ok(())
384-
}
385-
386362
#[command]
387363
pub async fn fetch_send<R: Runtime>(
388364
webview: Webview<R>,
@@ -435,6 +411,30 @@ pub async fn fetch_send<R: Runtime>(
435411
})
436412
}
437413

414+
#[command]
415+
pub async fn fetch_read_body<R: Runtime>(
416+
webview: Webview<R>,
417+
rid: ResourceId,
418+
stream_channel: Channel<tauri::ipc::InvokeResponseBody>,
419+
) -> crate::Result<()> {
420+
let res = {
421+
let mut resources_table = webview.resources_table();
422+
resources_table.take::<ReqwestResponse>(rid)?
423+
};
424+
425+
let mut res = Arc::into_inner(res).unwrap().0;
426+
427+
// send response through IPC channel
428+
while let Some(chunk) = res.chunk().await? {
429+
stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?;
430+
}
431+
432+
// send empty vector when done
433+
stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?;
434+
435+
Ok(())
436+
}
437+
438438
// forbidden headers per fetch spec https://fetch.spec.whatwg.org/#terminology-headers
439439
#[cfg(not(feature = "unsafe-headers"))]
440440
fn is_unsafe_header(header: &HeaderName) -> bool {

plugins/http/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
3636
.invoke_handler(tauri::generate_handler![
3737
commands::fetch,
3838
commands::fetch_cancel,
39-
commands::fetch_send
39+
commands::fetch_send,
40+
commands::fetch_read_body
4041
])
4142
.build()
4243
}

0 commit comments

Comments
 (0)