diff --git a/mime-parse/src/constants.rs b/mime-parse/src/constants.rs index 634c2bf..0a2d8eb 100644 --- a/mime-parse/src/constants.rs +++ b/mime-parse/src/constants.rs @@ -1,4 +1,5 @@ use super::{InternParams, Mime, ParamSource, Source}; +use crate::constants::names::RAR; macro_rules! mimes { ($($id:ident, $($piece:expr),+;)+) => ( @@ -60,7 +61,6 @@ macro_rules! mime_constant { ) } - #[cfg(test)] macro_rules! mime_constant_test { ($id:ident, $src:expr, $slash:expr) => ( @@ -135,12 +135,8 @@ impl Atoms { ); match params { - InternParams::Utf8(semicolon) => { - Atoms::intern_charset_utf8(s, slash, semicolon) - }, - InternParams::None => { - Atoms::intern_no_params(s, slash) - }, + InternParams::Utf8(semicolon) => Atoms::intern_charset_utf8(s, slash, semicolon), + InternParams::None => Atoms::intern_no_params(s, slash), } } @@ -199,7 +195,7 @@ impl Atoms { if sub == CSV { return Atoms::TEXT_CSV; } - }, + } 4 => { if sub == HTML { return Atoms::TEXT_HTML; @@ -222,7 +218,7 @@ impl Atoms { if sub == EVENT_STREAM { return Atoms::TEXT_EVENT_STREAM; } - }, + } 20 => { if sub == TAB_SEPARATED_VALUES { return Atoms::TEXT_TAB_SEPARATED_VALUES; @@ -232,20 +228,33 @@ impl Atoms { } } else if top == FONT { match sub.len() { + 3 => { + if sub == TTF { + return Atoms::FONT_TTF; + } + if sub == OTF { + return Atoms::FONT_OTF; + } + } 4 => { if sub == WOFF { return Atoms::FONT_WOFF; } - }, + } 5 => { if sub == WOFF2 { return Atoms::FONT_WOFF2; } - }, + } + 10 => { + if sub == COLLECTION { + return Atoms::FONT_COLLECTION; + } + } _ => (), } } - }, + } 5 => { if top == IMAGE { match sub.len() { @@ -269,14 +278,19 @@ impl Atoms { if sub == JPEG { return Atoms::IMAGE_JPEG; } - }, + if sub == WEBP { + return Atoms::IMAGE_WEBP; + } + if sub == AVIF { + return Atoms::IMAGE_AVIF; + } + } 7 => { if sub == SVG { return Atoms::IMAGE_SVG; } - }, + } _ => (), - } } else if top == VIDEO { match sub.len() { @@ -284,7 +298,20 @@ impl Atoms { if sub.as_bytes()[0] == b'*' { return Atoms::VIDEO_STAR; } - }, + } + 3 => { + if sub == AVI { + return Atoms::VIDEO_AVI; + } + if sub == MP4 { + return Atoms::VIDEO_MP4; + } + } + 4 => { + if sub == WEBM { + return Atoms::VIDEO_WEBM; + } + } _ => (), } } else if top == AUDIO { @@ -293,11 +320,38 @@ impl Atoms { if sub.as_bytes()[0] == b'*' { return Atoms::AUDIO_STAR; } - }, + } + 3 => { + if sub == OGG { + return Atoms::AUDIO_OGG; + } + if sub == MP4 { + return Atoms::AUDIO_MP4; + } + } + 4 => { + if sub == AIFF { + return Atoms::AUDIO_AIFF; + } + if sub == MIDI { + return Atoms::AUDIO_MIDI; + } + if sub == MPEG { + return Atoms::AUDIO_MPEG; + } + if sub == WAVE { + return Atoms::AUDIO_WAVE; + } + } + 5 => { + if sub == BASIC { + return Atoms::AUDIO_BASIC; + } + } _ => (), } } - }, + } 11 => { if top == APPLICATION { match sub.len() { @@ -305,27 +359,42 @@ impl Atoms { if sub == PDF { return Atoms::APPLICATION_PDF; } + if sub == ZIP { + return Atoms::APPLICATION_ZIP; + } + if sub == RAR { + return Atoms::APPLICATION_RAR; + } } 4 => { if sub == JSON { return Atoms::APPLICATION_JSON; } - }, + if sub == GZIP { + return Atoms::APPLICATION_GZIP; + } + } 7 => { if sub == MSGPACK { return Atoms::APPLICATION_MSGPACK; } - }, + } 10 => { if sub == JAVASCRIPT { return Atoms::APPLICATION_JAVASCRIPT; } - }, + if sub == POSTSCRIPT { + return Atoms::APPLICATION_POSTSCRIPT; + } + } 11 => { if sub == "dns-message" { return Atoms::APPLICATION_DNS; } - }, + if sub == VND_MS_FONTOBJECT { + return Atoms::APPLICATION_VND_MS_FONTOBJECT; + } + } 12 => { if sub == OCTET_STREAM { return Atoms::APPLICATION_OCTET_STREAM; @@ -406,10 +475,18 @@ names! { MSGPACK, "msgpack"; OCTET_STREAM, "octet-stream"; PDF, "pdf"; + ZIP, "zip"; + GZIP, "gzip"; + RAR, "rar"; + VND_MS_FONTOBJECT, "vnd.ms-fontobject"; + POSTSCRIPT, "postscript"; // common font/* WOFF, "woff"; WOFF2, "woff2"; + TTF, "ttf"; + OTF, "otf"; + COLLECTION, "collection"; // multipart/* FORM_DATA, "form-data"; @@ -418,6 +495,8 @@ names! { BMP, "bmp"; GIF, "gif"; JPEG, "jpeg"; + WEBP, "webp"; + AVIF, "avif"; PNG, "png"; SVG, "svg+xml"; @@ -426,6 +505,13 @@ names! { MPEG, "mpeg"; MP4, "mp4"; OGG, "ogg"; + AIFF, "aiff"; + MIDI, "midi"; + WAVE, "wave"; + + // video/* + AVI, "avi"; + WEBM, "webm"; // parameters CHARSET, "charset"; @@ -453,10 +539,15 @@ mimes! { IMAGE_GIF, "image/gif", 5; IMAGE_PNG, "image/png", 5; IMAGE_BMP, "image/bmp", 5; + IMAGE_WEBP, "image/webp", 5; + IMAGE_AVIF, "image/avif", 5; IMAGE_SVG, "image/svg+xml", 5, Some(9); FONT_WOFF, "font/woff", 4; FONT_WOFF2, "font/woff2", 4; + FONT_TTF, "font/ttf", 4; + FONT_OTF, "font/otf", 4; + FONT_COLLECTION, "font/collection", 4; APPLICATION_JSON, "application/json", 11; APPLICATION_JAVASCRIPT, "application/javascript", 11; @@ -466,6 +557,23 @@ mimes! { APPLICATION_MSGPACK, "application/msgpack", 11; APPLICATION_PDF, "application/pdf", 11; APPLICATION_DNS, "application/dns-message", 11; + APPLICATION_ZIP, "application/zip", 11; + APPLICATION_GZIP, "application/gzip", 11; + APPLICATION_RAR, "application/rar", 11; + APPLICATION_VND_MS_FONTOBJECT, "application/vnd.ms-fontobject", 11; + APPLICATION_POSTSCRIPT, "application/postscript", 11; + + AUDIO_BASIC, "audio/basic", 5; + AUDIO_MPEG, "audio/mpeg", 5; + AUDIO_MP4, "audio/mp4", 5; + AUDIO_OGG, "audio/ogg", 5; + AUDIO_AIFF, "audio/aiff", 5; + AUDIO_MIDI, "audio/midi", 5; + AUDIO_WAVE, "audio/wave", 5; + + VIDEO_AVI, "video/avi", 5; + VIDEO_MP4, "video/mp4", 5; + VIDEO_WEBM, "video/webm", 5; // media-ranges //@ MediaRange: @@ -475,4 +583,3 @@ mimes! { VIDEO_STAR, "video/*", 5; AUDIO_STAR, "audio/*", 5; } - diff --git a/src/constants.rs b/src/constants.rs index af4376e..eafab81 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,4 +1,3 @@ - macro_rules! mimes { ($(@ $kind:ident: $($id:ident, $src:expr;)+)+) => ( pub(super) mod mimes { @@ -31,35 +30,35 @@ macro_rules! mimes { } macro_rules! mime_constant { - ($kind:ident, $id:ident, $src:expr) => ( + ($kind:ident, $id:ident, $src:expr) => { mime_constant! { @DOC concat!("A `", stringify!($kind), "` representing `\"", $src, "\"`."), $kind, $id, $src } - ); - (@DOC $doc:expr, $kind:ident, $id:ident, $src:expr) => ( + }; + (@DOC $doc:expr, $kind:ident, $id:ident, $src:expr) => { #[doc = $doc] pub const $id: $kind = $kind { mime: mime_parse::constants::$id, }; - ) + }; } #[cfg(test)] macro_rules! mime_constant_test { - ($id:ident, $src:expr) => ({ + ($id:ident, $src:expr) => {{ let __mime = $id; // prevent ranges from being MediaTypes __mime.test_assert_asterisks(); - }) + }}; } #[cfg(test)] macro_rules! mime_constant_proc_macro_test { - (@MediaType, $id:ident, $src:expr) => ( + (@MediaType, $id:ident, $src:expr) => { // Test proc macro matches constants #[cfg(feature = "macro")] { @@ -71,8 +70,8 @@ macro_rules! mime_constant_proc_macro_test { assert_ne!(macroed.mime.private_atom(), 0); assert_eq!(constant.mime.private_atom(), macroed.mime.private_atom()); } - ); - (@MediaRange, $id:ident, $src:expr) => (); + }; + (@MediaRange, $id:ident, $src:expr) => {}; } mimes! { @@ -96,10 +95,15 @@ mimes! { IMAGE_GIF, "image/gif"; IMAGE_PNG, "image/png"; IMAGE_BMP, "image/bmp"; + IMAGE_WEBP, "image/webp"; + IMAGE_AVIF, "image/avif"; IMAGE_SVG, "image/svg+xml"; FONT_WOFF, "font/woff"; FONT_WOFF2, "font/woff2"; + FONT_TTF, "font/ttf"; + FONT_OTF, "font/otf"; + FONT_COLLECTION, "font/collection"; APPLICATION_JSON, "application/json"; APPLICATION_JAVASCRIPT, "application/javascript"; @@ -109,6 +113,23 @@ mimes! { APPLICATION_MSGPACK, "application/msgpack"; APPLICATION_PDF, "application/pdf"; APPLICATION_DNS, "application/dns-message"; + APPLICATION_ZIP, "application/zip"; + APPLICATION_GZIP, "application/gzip"; + APPLICATION_RAR, "application/rar"; + APPLICATION_VND_MS_FONTOBJECT, "application/vnd.ms-fontobject"; + APPLICATION_POSTSCRIPT, "application/postscript"; + + AUDIO_BASIC, "audio/basic"; + AUDIO_MPEG, "audio/mpeg"; + AUDIO_MP4, "audio/mp4"; + AUDIO_OGG, "audio/ogg"; + AUDIO_AIFF, "audio/aiff"; + AUDIO_MIDI, "audio/midi"; + AUDIO_WAVE, "audio/wave"; + + VIDEO_AVI, "video/avi"; + VIDEO_MP4, "video/mp4"; + VIDEO_WEBM, "video/webm"; // media-ranges @ MediaRange: @@ -118,4 +139,3 @@ mimes! { VIDEO_STAR, "video/*"; AUDIO_STAR, "audio/*"; } -