rustyphoenixrequest 1.6.1

This library provides methods to mock request API. This is the Rust equivalent of https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/network/PhoenixRequest
Documentation
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

///Mime type of Http response
#[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,
}

///Get the content type of the corresponding PMimeType
/// # Parameters
/// - `mimetype` : type of the content
/// # Returns
/// Corresponding String
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"),
	}
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type
		// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Encoding
		// HTTP/1.1 200
		// content-encoding: br
		// content-type: text/javascript; charset=utf-8
		
		// Content-Encoding: gzip
		// Content-Encoding: compress
		// Content-Encoding: deflate
		// Content-Encoding: br
		// Content-Encoding: zstd
		// Content-Encoding: dcb
		// Content-Encoding: dcz
// 
		// // Multiple, in the order in which they were applied
		// Content-Encoding: deflate, gzip
		
		
		// text/css
		// 
		// text/html for HTML documents.
		// text/plain for plain text.
		// text/css for Cascading Style Sheets.
		// text/javascript for JavaScript files.
		// text/markdown for Markdown files.
		// application/octet-stream for binary files where user action is expected.
		
		// https://www.iana.org/assignments/media-types/media-types.xhtml
		// https://www.iana.org/assignments/media-types/media-types.xhtml#image
// 		image/jpeg
// 		image/png
// 		image/svg+xml
// 		image/webp
// 		image/gif
// 		image/bmp
// 		text/csv
// 		text/markdown
// 		text/xml
// 		text/calendar
// 		video/H264
// 		video/ogg
// 		video/mp4
// 		audio/ogg
// 		audio/mp4
// 		audio/aac
// 		audio/ac3
// 		
// 		model/obj
// 		model/mtl
// 		
// 		font/collection
// 		font/otf
// 		font/sfnt
// 		font/ttf
// 		font/woff
// 		font/woff2
		
		// vary: Accept-Encoding
		// date: Fri, 21 Jun 2024 14:02:25 GMT
		// content-length: 2978

		#[cfg(test)]
mod tests {
//{We need the previously defined functions of the crate :
	use super::*;
	
	///Get the get_content_type function
	#[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"));
	}
}