static handler: guess content type

This commit is contained in:
Armaël Guéneau 2025-01-02 12:45:00 +01:00
parent 52e9413349
commit f5c29ceffb
3 changed files with 17 additions and 2 deletions

11
Cargo.lock generated
View file

@ -1184,6 +1184,7 @@ dependencies = [
"include_dir",
"lazy_static",
"lettre",
"new_mime_guess",
"rand",
"reqwest 0.12.9",
"serde",
@ -2008,6 +2009,16 @@ dependencies = [
"tempfile",
]
[[package]]
name = "new_mime_guess"
version = "4.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02a2dfb3559d53e90b709376af1c379462f7fb3085a0177deb73e6ea0d99eff4"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "nom"
version = "7.1.3"

View file

@ -23,6 +23,7 @@ lettre = { version = "0.11", features = ["builder", "smtp-transport", "rustls-tl
include_dir = "0.7"
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
aws-sdk-s3 = "1.66.0"
new_mime_guess = "4"
[profile.profiling]
inherits = "dev"

View file

@ -443,9 +443,12 @@ async fn get_static_(
) -> impl IntoResponse {
eprintln!("GET {}", uri);
match STATIC_DIR.get_file(filename) {
match STATIC_DIR.get_file(&filename) {
None => (StatusCode::NOT_FOUND, "404 Not found").into_response(),
Some(page) => page.contents().into_response(),
Some(page) => {
let mime = new_mime_guess::from_path(&filename).first_or_octet_stream();
([(header::CONTENT_TYPE, mime.to_string())], page.contents()).into_response()
},
}
}