diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index 1c9e3f0e..18953121 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -359,30 +359,6 @@ pub fn fetch_cancel(webview: Webview, rid: ResourceId) -> crate:: Ok(()) } -#[command] -pub async fn fetch_read_body( - webview: Webview, - rid: ResourceId, - stream_channel: Channel, -) -> crate::Result<()> { - let res = { - let mut resources_table = webview.resources_table(); - resources_table.take::(rid)? - }; - - let mut res = Arc::into_inner(res).unwrap().0; - - // send response through IPC channel - while let Some(chunk) = res.chunk().await? { - stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?; - } - - // send empty vector when done - stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?; - - Ok(()) -} - #[command] pub async fn fetch_send( webview: Webview, @@ -435,6 +411,30 @@ pub async fn fetch_send( }) } +#[command] +pub async fn fetch_read_body( + webview: Webview, + rid: ResourceId, + stream_channel: Channel, +) -> crate::Result<()> { + let res = { + let mut resources_table = webview.resources_table(); + resources_table.take::(rid)? + }; + + let mut res = Arc::into_inner(res).unwrap().0; + + // send response through IPC channel + while let Some(chunk) = res.chunk().await? { + stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?; + } + + // send empty vector when done + stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?; + + Ok(()) +} + // forbidden headers per fetch spec https://fetch.spec.whatwg.org/#terminology-headers #[cfg(not(feature = "unsafe-headers"))] fn is_unsafe_header(header: &HeaderName) -> bool { diff --git a/plugins/http/src/lib.rs b/plugins/http/src/lib.rs index 4e11e561..65829e09 100644 --- a/plugins/http/src/lib.rs +++ b/plugins/http/src/lib.rs @@ -36,7 +36,8 @@ pub fn init() -> TauriPlugin { .invoke_handler(tauri::generate_handler![ commands::fetch, commands::fetch_cancel, - commands::fetch_send + commands::fetch_send, + commands::fetch_read_body ]) .build() }