mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-05 01:44:34 +03:00
This reverts commit 39443b4350
.
This commit is contained in:
parent
23859f7502
commit
2d9c2b4724
@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"tauri": "patch"
|
|
||||||
---
|
|
||||||
|
|
||||||
Set the correct mimetype when streaming files through `asset:` protocol
|
|
@ -507,9 +507,7 @@ impl<R: Runtime> WindowManager<R> {
|
|||||||
use crate::api::file::SafePathBuf;
|
use crate::api::file::SafePathBuf;
|
||||||
use tokio::io::{AsyncReadExt, AsyncSeekExt};
|
use tokio::io::{AsyncReadExt, AsyncSeekExt};
|
||||||
use url::Position;
|
use url::Position;
|
||||||
let state = self.state();
|
let asset_scope = self.state().get::<crate::Scopes>().asset_protocol.clone();
|
||||||
let asset_scope = state.get::<crate::Scopes>().asset_protocol.clone();
|
|
||||||
let mime_type_cache = MimeTypeCache::default();
|
|
||||||
pending.register_uri_scheme_protocol("asset", move |request| {
|
pending.register_uri_scheme_protocol("asset", move |request| {
|
||||||
let parsed_path = Url::parse(request.uri())?;
|
let parsed_path = Url::parse(request.uri())?;
|
||||||
let filtered_path = &parsed_path[..Position::AfterPath];
|
let filtered_path = &parsed_path[..Position::AfterPath];
|
||||||
@ -624,7 +622,7 @@ impl<R: Runtime> WindowManager<R> {
|
|||||||
response = response.header(k, v);
|
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)
|
response.mimetype(&mime_type).status(status_code).body(data)
|
||||||
} else {
|
} else {
|
||||||
match crate::async_runtime::safe_block_on(async move { tokio::fs::read(path_).await }) {
|
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<Mutex<HashMap<String, String>>>);
|
|
||||||
|
|
||||||
#[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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::replace_with_callback;
|
use super::replace_with_callback;
|
||||||
|
Loading…
Reference in New Issue
Block a user