From 2d9c2b472416339829f9113f976f193bf8e0665f Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 30 Sep 2022 20:38:20 +0200 Subject: [PATCH] Revert "fix(core): set correct mimetype for asset protocol streams, closes #5203 (#5210)" This reverts commit 39443b4350bd208c4d6eec5e1095f215199f8aa3. --- .../asset-protocol-streaming-mime-type.md | 5 ---- core/tauri/src/manager.rs | 26 ++----------------- 2 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 .changes/asset-protocol-streaming-mime-type.md diff --git a/.changes/asset-protocol-streaming-mime-type.md b/.changes/asset-protocol-streaming-mime-type.md deleted file mode 100644 index 43c99d2c9be..00000000000 --- a/.changes/asset-protocol-streaming-mime-type.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"tauri": "patch" ---- - -Set the correct mimetype when streaming files through `asset:` protocol diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index e04dc3d4b70..4ee026b5e49 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -507,9 +507,7 @@ impl WindowManager { use crate::api::file::SafePathBuf; use tokio::io::{AsyncReadExt, AsyncSeekExt}; use url::Position; - let state = self.state(); - let asset_scope = state.get::().asset_protocol.clone(); - let mime_type_cache = MimeTypeCache::default(); + let asset_scope = self.state().get::().asset_protocol.clone(); pending.register_uri_scheme_protocol("asset", move |request| { let parsed_path = Url::parse(request.uri())?; let filtered_path = &parsed_path[..Position::AfterPath]; @@ -624,7 +622,7 @@ impl WindowManager { response = response.header(k, v); } - let mime_type = mime_type_cache.get_or_insert(&data, &path); + let mime_type = MimeType::parse(&data, &path); response.mimetype(&mime_type).status(status_code).body(data) } else { match crate::async_runtime::safe_block_on(async move { tokio::fs::read(path_).await }) { @@ -1429,26 +1427,6 @@ fn request_to_path(request: &tauri_runtime::http::Request, base_url: &str) -> St } } -// key is uri/path, value is the store mime type -#[cfg(protocol_asset)] -#[derive(Debug, Clone, Default)] -struct MimeTypeCache(Arc>>); - -#[cfg(protocol_asset)] -impl MimeTypeCache { - pub fn get_or_insert(&self, content: &[u8], uri: &str) -> String { - let mut cache = self.0.lock().unwrap(); - let uri = uri.to_string(); - if let Some(mime_type) = cache.get(&uri) { - mime_type.clone() - } else { - let mime_type = MimeType::parse(content, &uri); - cache.insert(uri, mime_type.clone()); - mime_type - } - } -} - #[cfg(test)] mod tests { use super::replace_with_callback;