mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-14 18:57:59 +01:00
Replace mime_guess dep with a simple function
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -94,7 +94,6 @@ dependencies = [
|
||||
"clap_mangen",
|
||||
"config",
|
||||
"futures-util",
|
||||
"mime_guess",
|
||||
"nix 0.30.1",
|
||||
"reqwest",
|
||||
"rgb",
|
||||
|
||||
@@ -34,7 +34,6 @@ tokio = { version = "1.44.2", features = ["full"] }
|
||||
futures-util = "0.3.31"
|
||||
tokio-stream = { version = "0.1.17", features = ["sync"] }
|
||||
rust-embed = "8.2.0"
|
||||
mime_guess = "2.0.4"
|
||||
tower-http = { version = "0.6.2", features = ["trace"] }
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::future;
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
|
||||
use axum::extract::connect_info::ConnectInfo;
|
||||
use axum::extract::ws::{self, CloseCode, CloseFrame, Message, WebSocket, WebSocketUpgrade};
|
||||
@@ -71,15 +72,30 @@ async fn static_handler(uri: Uri) -> impl IntoResponse {
|
||||
|
||||
match Assets::get(path) {
|
||||
Some(content) => {
|
||||
let mime = mime_guess::from_path(path).first_or_octet_stream();
|
||||
let mime = mime_from_path(path);
|
||||
|
||||
([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response()
|
||||
([(header::CONTENT_TYPE, mime)], content.data).into_response()
|
||||
}
|
||||
|
||||
None => (StatusCode::NOT_FOUND, "404").into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
fn mime_from_path(path: &str) -> &str {
|
||||
let lowercase_path = &path.to_lowercase();
|
||||
|
||||
let ext = Path::new(lowercase_path)
|
||||
.extension()
|
||||
.and_then(|e| e.to_str());
|
||||
|
||||
match ext {
|
||||
Some("html") => "text/html",
|
||||
Some("js") => "text/javascript",
|
||||
Some("css") => "text/css",
|
||||
Some(_) | None => "application/octet-stream",
|
||||
}
|
||||
}
|
||||
|
||||
async fn ws_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
|
||||
Reference in New Issue
Block a user