mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
Switch from tree_magic to mime_guess
This commit is contained in:
parent
3a05cefe6f
commit
2c4118b590
3 changed files with 21 additions and 97 deletions
|
|
@ -132,15 +132,15 @@ async fn send_response<W: Write + Unpin>(url: &Url, mut stream: W) -> Result {
|
|||
|
||||
// Make sure the file opens successfully before sending the success header.
|
||||
let mut file = async_std::fs::File::open(&path).await?;
|
||||
|
||||
|
||||
// Send header.
|
||||
if path.extension() == Some(OsStr::new("gmi")) {
|
||||
respond(&mut stream, "20", &["text/gemini"]).await?;
|
||||
} else {
|
||||
let mime = tree_magic_mini::from_filepath(&path).ok_or("Can't read file")?;
|
||||
respond(&mut stream, "20", &[mime]).await?;
|
||||
let mime = mime_guess::from_path(&path).first_or_octet_stream();
|
||||
respond(&mut stream, "20", &[mime.essence_str()]).await?;
|
||||
}
|
||||
|
||||
|
||||
// Send body.
|
||||
async_std::io::copy(&mut file, &mut stream).await?;
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue