Skip to content

Commit

Permalink
fix(core): set correct mimetype for asset protocol streames, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Sep 16, 2022
1 parent 2954f6d commit ebf9b3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/asset-protocol-streaming-mime-type.md
@@ -0,0 +1,5 @@
---
"tauri": "patch"
---

Set the correct mimetype when streaming files through `asset:` protocol
16 changes: 15 additions & 1 deletion core/tauri/src/manager.rs
Expand Up @@ -626,7 +626,21 @@ impl<R: Runtime> WindowManager<R> {
response = response.header(k, v);
}

let mime_type = MimeType::parse(&data, &path);
let mime_type = {
use once_cell::sync::Lazy;
static MIME_TYPES_CACHE: Lazy<Arc<Mutex<HashMap<String, String>>>> =
Lazy::new(Default::default);

let mut cache = MIME_TYPES_CACHE.lock().unwrap();
if let Some(mime_type) = cache.get(&path) {
mime_type.clone()
} else {
let mime_type = MimeType::parse(&data, &path);
cache.insert(path, mime_type.clone());
mime_type
}
};

response.mimetype(&mime_type).status(status_code).body(data)
} else {
match crate::async_runtime::safe_block_on(async move { tokio::fs::read(path_).await }) {
Expand Down
14 changes: 7 additions & 7 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ebf9b3a

Please sign in to comment.