#[derive(Default, Debug, PartialEq, Copy, Clone)]
pub enum PMimeType {
#[default]
TextPlain,
TextHtml,
TextCss,
TextJavascript,
TextMarkdown,
TextCsv,
TextXml,
TextCalendar,
ImageJpeg,
ImagePng,
ImageSvgXml,
ImageWebp,
ImageGif,
ImageBmp,
ModelObj,
ModelMtl,
FontCollection,
FontOtf,
FontSfnt,
FontTtf,
FontWoff,
FontWoff2,
VideoH264,
VideoOgg,
VideoMp4,
AudioOgg,
AudioMp4,
AudioAac,
AudioAc3,
}
pub fn get_content_type(mimetype: &PMimeType) -> String {
match mimetype {
PMimeType::TextPlain => String::from("content-type: text/plain ; charset=utf-8"),
PMimeType::TextHtml => String::from("content-type: text/html ; charset=utf-8"),
PMimeType::TextCss => String::from("content-type: text/css ; charset=utf-8"),
PMimeType::TextJavascript => String::from("content-type: text/javascript ; charset=utf-8"),
PMimeType::TextMarkdown => String::from("content-type: text/markdown ; charset=utf-8"),
PMimeType::TextCsv => String::from("content-type: text/csv ; charset=utf-8"),
PMimeType::TextXml => String::from("content-type: text/xml ; charset=utf-8"),
PMimeType::TextCalendar => String::from("content-type: text/calendar ; charset=utf-8"),
PMimeType::ImageJpeg => String::from("content-type: image/jpeg"),
PMimeType::ImagePng => String::from("content-type: image/png"),
PMimeType::ImageSvgXml => String::from("content-type: image/svg+xml"),
PMimeType::ImageWebp => String::from("content-type: image/webp"),
PMimeType::ImageGif => String::from("content-type: image/gif"),
PMimeType::ImageBmp => String::from("content-type: image/bmp"),
PMimeType::ModelObj => String::from("content-type: model/obj"),
PMimeType::ModelMtl => String::from("content-type: model/mlt"),
PMimeType::FontCollection => String::from("content-type: font/collection"),
PMimeType::FontOtf => String::from("content-type: font/otf"),
PMimeType::FontSfnt => String::from("content-type: font/sfnt"),
PMimeType::FontTtf => String::from("content-type: font/ttf"),
PMimeType::FontWoff => String::from("content-type: font/woff"),
PMimeType::FontWoff2 => String::from("content-type: font/woff2"),
PMimeType::VideoH264 => String::from("content-type: video/H264"),
PMimeType::VideoOgg => String::from("content-type: video/ogg"),
PMimeType::VideoMp4 => String::from("content-type: video/mp4"),
PMimeType::AudioOgg => String::from("content-type: audio/ogg"),
PMimeType::AudioMp4 => String::from("content-type: audio/mp4"),
PMimeType::AudioAac => String::from("content-type: audio/aac"),
PMimeType::AudioAc3 => String::from("content-type: audio/ac3"),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_content_type(){
assert_eq!(get_content_type(&PMimeType::TextPlain), String::from("content-type: text/plain ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextHtml), String::from("content-type: text/html ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextCss), String::from("content-type: text/css ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextJavascript), String::from("content-type: text/javascript ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextMarkdown), String::from("content-type: text/markdown ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextCsv), String::from("content-type: text/csv ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextXml), String::from("content-type: text/xml ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::TextCalendar), String::from("content-type: text/calendar ; charset=utf-8"));
assert_eq!(get_content_type(&PMimeType::ImageJpeg), String::from("content-type: image/jpeg"));
assert_eq!(get_content_type(&PMimeType::ImagePng), String::from("content-type: image/png"));
assert_eq!(get_content_type(&PMimeType::ImageSvgXml), String::from("content-type: image/svg+xml"));
assert_eq!(get_content_type(&PMimeType::ImageWebp), String::from("content-type: image/webp"));
assert_eq!(get_content_type(&PMimeType::ImageGif), String::from("content-type: image/gif"));
assert_eq!(get_content_type(&PMimeType::ImageBmp), String::from("content-type: image/bmp"));
assert_eq!(get_content_type(&PMimeType::ModelObj), String::from("content-type: model/obj"));
assert_eq!(get_content_type(&PMimeType::ModelMtl), String::from("content-type: model/mlt"));
assert_eq!(get_content_type(&PMimeType::FontCollection), String::from("content-type: font/collection"));
assert_eq!(get_content_type(&PMimeType::FontOtf), String::from("content-type: font/otf"));
assert_eq!(get_content_type(&PMimeType::FontSfnt), String::from("content-type: font/sfnt"));
assert_eq!(get_content_type(&PMimeType::FontTtf), String::from("content-type: font/ttf"));
assert_eq!(get_content_type(&PMimeType::FontWoff), String::from("content-type: font/woff"));
assert_eq!(get_content_type(&PMimeType::FontWoff2), String::from("content-type: font/woff2"));
assert_eq!(get_content_type(&PMimeType::VideoH264), String::from("content-type: video/H264"));
assert_eq!(get_content_type(&PMimeType::VideoOgg), String::from("content-type: video/ogg"));
assert_eq!(get_content_type(&PMimeType::VideoMp4), String::from("content-type: video/mp4"));
assert_eq!(get_content_type(&PMimeType::AudioOgg), String::from("content-type: audio/ogg"));
assert_eq!(get_content_type(&PMimeType::AudioMp4), String::from("content-type: audio/mp4"));
assert_eq!(get_content_type(&PMimeType::AudioAac), String::from("content-type: audio/aac"));
assert_eq!(get_content_type(&PMimeType::AudioAc3), String::from("content-type: audio/ac3"));
}
}