diff --git a/plugins/http/guest-js/index.ts b/plugins/http/guest-js/index.ts index 7787da7e..760f0648 100644 --- a/plugins/http/guest-js/index.ts +++ b/plugins/http/guest-js/index.ts @@ -106,16 +106,6 @@ export interface DangerousSettings { acceptInvalidHostnames?: boolean } -/** - * Stream Packet for IPC - */ -export interface StreamMessage { - /** - * The chunk - an array of bytes sent from Rust. - */ - bytes: Uint8Array -} - const ERROR_REQUEST_CANCELLED = 'Request canceled' /** @@ -196,18 +186,18 @@ export async function fetch( throw new Error(ERROR_REQUEST_CANCELLED) } - const streamChannel = new Channel() + const streamChannel = new Channel() const readableStreamBody = new ReadableStream({ start: (controller) => { - streamChannel.onmessage = (res: StreamMessage) => { + streamChannel.onmessage = (res: Uint8Array) => { // close early if aborted if (signal?.aborted) { controller.error(ERROR_REQUEST_CANCELLED) return } - if (!res.bytes.length) { + if (!res.length) { controller.close() return } diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index 1a86da57..05631660 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -129,12 +129,6 @@ pub struct BasicAuth { password: String, } -#[derive(Clone, Serialize)] -pub struct StreamMessage { - #[serde(with = "serde_bytes")] - bytes: Vec -} - #[inline] fn proxy_creator( url_or_config: UrlOrConfig, @@ -190,7 +184,7 @@ pub async fn fetch( client_config: ClientConfig, command_scope: CommandScope, global_scope: GlobalScope, - stream_channel: Channel + stream_channel: Channel ) -> crate::Result { let ClientConfig { method, @@ -329,11 +323,11 @@ pub async fn fetch( // send response through IPC channel while let Some(chunk) = res.chunk().await? { - stream_channel.send(StreamMessage{bytes: chunk.to_vec()})?; + stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(chunk.to_vec()))?; } // send empty vector when done - stream_channel.send(StreamMessage{bytes: Vec::new()})?; + stream_channel.send(tauri::ipc::InvokeResponseBody::Raw(Vec::new()))?; // return that response Ok(res)