http_types_rs/mime/
constants.rs

1use crate::mime::Mime;
2use std::borrow::Cow;
3
4macro_rules! utf8_mime_const {
5    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
6        mime_const!(with_params, $name, $desc, $base, $sub, true, ";charset=utf-8");
7    };
8}
9macro_rules! mime_const {
10    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
11        mime_const!(with_params, $name, $desc, $base, $sub, false, "");
12    };
13
14    (with_params, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
15        mime_const!(
16            doc_expanded,
17            $name,
18            $desc,
19            $base,
20            $sub,
21            $is_utf8,
22            concat!(
23                "Content-Type for ",
24                $desc,
25                ".\n\n# Mime Type\n\n```text\n",
26                $base,
27                "/",
28                $sub,
29                $doccomment,
30                "\n```"
31            )
32        );
33    };
34
35    (doc_expanded, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
36        #[doc = $doccomment]
37        pub const $name: Mime = Mime {
38            essence: Cow::Borrowed(concat!($base, "/", $sub)),
39            basetype: Cow::Borrowed($base),
40            subtype: Cow::Borrowed($sub),
41            is_utf8: $is_utf8,
42            params: vec![],
43        };
44    };
45}
46
47utf8_mime_const!(JAVASCRIPT, "JavaScript", "text", "javascript");
48utf8_mime_const!(CSS, "CSS", "text", "css");
49utf8_mime_const!(HTML, "HTML", "text", "html");
50utf8_mime_const!(PLAIN, "Plain text", "text", "plain");
51utf8_mime_const!(XML, "XML", "application", "xml");
52utf8_mime_const!(RSS, "RSS Feed", "application", "rss+xml");
53utf8_mime_const!(ATOM, "Atom Feed", "application", "atom+xml");
54mime_const!(ANY, "matching anything", "*", "*");
55mime_const!(JSON, "JSON", "application", "json");
56mime_const!(SSE, "Server Sent Events", "text", "event-stream");
57mime_const!(BYTE_STREAM, "byte streams", "application", "octet-stream");
58mime_const!(FORM, "forms", "application", "x-www-form-urlencoded");
59mime_const!(MULTIPART_FORM, "multipart forms", "multipart", "form-data");
60mime_const!(WASM, "webassembly", "application", "wasm");
61
62// Images
63// https://www.iana.org/assignments/media-types/media-types.xhtml#image
64mime_const!(BMP, "BMP images", "image", "bmp");
65mime_const!(JPEG, "JPEG images", "image", "jpeg");
66mime_const!(PNG, "PNG images", "image", "png");
67mime_const!(SVG, "SVG", "image", "svg+xml");
68mime_const!(WEBP, "WebP images", "image", "webp");
69
70// Audio
71// https://www.iana.org/assignments/media-types/media-types.xhtml#audio
72mime_const!(MIDI, "MIDI audio", "audio", "midi");
73mime_const!(MP3, "MPEG audio layer 3", "audio", "mpeg");
74mime_const!(OGG, "Ogg vorbis audio", "audio", "ogg");
75mime_const!(OPUS, "Opus audio", "audio", "opus");
76mime_const!(M4A, "MPEG audio layer 4", "audio", "mp4");
77
78// Video
79// https://www.iana.org/assignments/media-types/media-types.xhtml#video
80mime_const!(MP4, "MPEG video layer 4", "video", "mp4");
81mime_const!(MPEG, "MPEG video", "video", "mpeg");
82mime_const!(WEBM, "WebM video", "video", "webm");
83mime_const!(AVI, "Microsoft AVI video", "video", "x-msvideo");
84// There are multiple `.ico` mime types known, but `image/x-icon`
85// is what most browser use. See:
86// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
87mime_const!(ICO, "ICO icons", "image", "x-icon");
88
89// Fonts
90// https://www.iana.org/assignments/media-types/media-types.xhtml#font
91mime_const!(OTF, "OTF", "font", "otf");
92mime_const!(TTF, "TTF", "font", "ttf");
93mime_const!(WOFF, "WOFF", "font", "woff");
94mime_const!(WOFF2, "WOFF2", "font", "woff2");
95
96// Archives
97mime_const!(ZIP, "Zip archive", "application", "zip");
98mime_const!(SEVENZIP, "7Zip archive", "application", "x-7z-compressed");