refactor mime type support detection in image loader to allow for deferred handling and appended encoding info (#5686)
as recommended by @lucasmerlin in #5679 * Closes #5679 * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
6b38fd39a1
commit
1aced06e47
|
|
@ -36,11 +36,21 @@ fn is_supported_uri(uri: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_supported_mime(mime: &str) -> bool {
|
fn is_supported_mime(mime: &str) -> bool {
|
||||||
// This is the default mime type for binary files, so this might actually be a valid image,
|
// some mime types e.g. reflect binary files or mark the content as a download, which
|
||||||
// let's relay on image's format guessing
|
// may be a valid image or not, in this case, defer the decision on the format guessing
|
||||||
if mime == "application/octet-stream" {
|
// or the image crate and return true here
|
||||||
return true;
|
let mimes_to_defer = [
|
||||||
|
"application/octet-stream",
|
||||||
|
"application/x-msdownload",
|
||||||
|
"application/force-download",
|
||||||
|
];
|
||||||
|
for m in &mimes_to_defer {
|
||||||
|
// use contains instead of direct equality, as e.g. encoding info might be appended
|
||||||
|
if mime.contains(m) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uses only the enabled image crate features
|
// Uses only the enabled image crate features
|
||||||
ImageFormat::all()
|
ImageFormat::all()
|
||||||
.filter(ImageFormat::reading_enabled)
|
.filter(ImageFormat::reading_enabled)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue