feat: Use mime_guess crate to support more mime types
This commit is contained in:
parent
d69b4d10f6
commit
18aa9d8a51
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -288,6 +288,16 @@ version = "0.3.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime_guess"
|
||||||
|
version = "2.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
|
||||||
|
dependencies = [
|
||||||
|
"mime",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
@ -399,7 +409,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static-serve"
|
name = "static-serve"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"bytes",
|
"bytes",
|
||||||
@ -413,11 +423,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static-serve-macro"
|
name = "static-serve-macro"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"display_full_error",
|
"display_full_error",
|
||||||
"flate2",
|
"flate2",
|
||||||
"glob",
|
"glob",
|
||||||
|
"mime_guess",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"sha1",
|
"sha1",
|
||||||
@ -517,6 +528,12 @@ version = "1.18.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicase"
|
||||||
|
version = "2.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
@ -16,6 +16,7 @@ proc-macro = true
|
|||||||
display_full_error = "1.1"
|
display_full_error = "1.1"
|
||||||
flate2 = "1.1"
|
flate2 = "1.1"
|
||||||
glob = "0.3"
|
glob = "0.3"
|
||||||
|
mime_guess = "2.0.5"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
sha1 = "0.10"
|
sha1 = "0.10"
|
||||||
|
@ -12,6 +12,7 @@ use std::{
|
|||||||
use display_full_error::DisplayFullError;
|
use display_full_error::DisplayFullError;
|
||||||
use flate2::write::GzEncoder;
|
use flate2::write::GzEncoder;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
use mime_guess::MimeGuess;
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::{quote, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
use sha1::{Digest as _, Sha1};
|
use sha1::{Digest as _, Sha1};
|
||||||
@ -357,15 +358,11 @@ fn maybe_get_compressed(compressed: &[u8], contents: &[u8]) -> Option<LitByteStr
|
|||||||
.then(|| LitByteStr::new(compressed, Span::call_site()))
|
.then(|| LitByteStr::new(compressed, Span::call_site()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_content_type(path: &Path) -> Result<&'static str, error::Error> {
|
fn file_content_type(path: &Path) -> Result<String, error::Error> {
|
||||||
match path.extension() {
|
if let Some(mime) = MimeGuess::from_path(path).first() {
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("css") => Ok("text/css"),
|
Ok(mime.essence_str().to_string())
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("js") => Ok("text/javascript"),
|
} else {
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("txt") => Ok("text/plain"),
|
Err(error::Error::UnknownFileExtension(path.extension().map(Into::into)))
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("woff") => Ok("font/woff"),
|
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("woff2") => Ok("font/woff2"),
|
|
||||||
Some(ext) if ext.eq_ignore_ascii_case("svg") => Ok("image/svg+xml"),
|
|
||||||
ext => Err(error::Error::UnknownFileExtension(ext.map(Into::into))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user