use std::path::Path;
use crate::{
cache::Cache,
config::Config,
hteapot::{HttpRequest, HttpResponse},
logger::Logger,
};
pub fn get_mime_tipe(path: &String) -> String {
let extension = Path::new(path.as_str())
.extension()
.map(|ext| ext.to_str().unwrap_or(""))
.unwrap_or("");
let mimetipe = match extension {
"html" | "htm" => "text/html; charset=utf-8",
"js" => "text/javascript",
"mjs" => "text/javascript",
"css" => "text/css",
"json" => "application/json",
"xml" => "application/xml",
"txt" => "text/plain",
"md" => "text/markdown",
"csv" => "text/csv",
"ico" => "image/x-icon",
"png" => "image/png",
"jpg" | "jpeg" => "image/jpeg",
"gif" => "image/gif",
"svg" => "image/svg+xml",
"webp" => "image/webp",
"bmp" => "image/bmp",
"tiff" | "tif" => "image/tiff",
"mp3" => "audio/mpeg",
"wav" => "audio/wav",
"ogg" => "audio/ogg",
"flac" => "audio/flac",
"mp4" => "video/mp4",
"webm" => "video/webm",
"avi" => "video/x-msvideo",
"mkv" => "video/x-matroska",
"pdf" => "application/pdf",
"doc" => "application/msword",
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"xls" => "application/vnd.ms-excel",
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"ppt" => "application/vnd.ms-powerpoint",
"pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"zip" => "application/zip",
"tar" => "application/x-tar",
"gz" => "application/gzip",
"7z" => "application/x-7z-compressed",
"rar" => "application/vnd.rar",
"ttf" => "font/ttf",
"otf" => "font/otf",
"woff" => "font/woff",
"woff2" => "font/woff2",
_ => "application/octet-stream",
};
mimetipe.to_string()
}
pub struct Context<'a> {
pub request: &'a HttpRequest,
pub log: &'a Logger,
pub config: &'a Config,
pub cache: Option<&'a mut Cache<HttpRequest, HttpResponse>>,
}