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"
|
||||
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]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.5"
|
||||
@ -399,7 +409,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "static-serve"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"bytes",
|
||||
@ -413,11 +423,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "static-serve-macro"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"display_full_error",
|
||||
"flate2",
|
||||
"glob",
|
||||
"mime_guess",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"sha1",
|
||||
@ -517,6 +528,12 @@ version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
|
@ -16,6 +16,7 @@ proc-macro = true
|
||||
display_full_error = "1.1"
|
||||
flate2 = "1.1"
|
||||
glob = "0.3"
|
||||
mime_guess = "2.0.5"
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
sha1 = "0.10"
|
||||
|
@ -12,6 +12,7 @@ use std::{
|
||||
use display_full_error::DisplayFullError;
|
||||
use flate2::write::GzEncoder;
|
||||
use glob::glob;
|
||||
use mime_guess::MimeGuess;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{quote, ToTokens};
|
||||
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()))
|
||||
}
|
||||
|
||||
fn file_content_type(path: &Path) -> Result<&'static str, error::Error> {
|
||||
match path.extension() {
|
||||
Some(ext) if ext.eq_ignore_ascii_case("css") => Ok("text/css"),
|
||||
Some(ext) if ext.eq_ignore_ascii_case("js") => Ok("text/javascript"),
|
||||
Some(ext) if ext.eq_ignore_ascii_case("txt") => Ok("text/plain"),
|
||||
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))),
|
||||
fn file_content_type(path: &Path) -> Result<String, error::Error> {
|
||||
if let Some(mime) = MimeGuess::from_path(path).first() {
|
||||
Ok(mime.essence_str().to_string())
|
||||
} else {
|
||||
Err(error::Error::UnknownFileExtension(path.extension().map(Into::into)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user