Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature video extension #159

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 130 additions & 23 deletions mime-parse/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{InternParams, Mime, ParamSource, Source};
use crate::constants::names::RAR;

macro_rules! mimes {
($($id:ident, $($piece:expr),+;)+) => (
Expand Down Expand Up @@ -60,7 +61,6 @@ macro_rules! mime_constant {
)
}


#[cfg(test)]
macro_rules! mime_constant_test {
($id:ident, $src:expr, $slash:expr) => (
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -199,7 +195,7 @@ impl Atoms {
if sub == CSV {
return Atoms::TEXT_CSV;
}
},
}
4 => {
if sub == HTML {
return Atoms::TEXT_HTML;
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -269,22 +278,40 @@ 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() {
1 => {
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 {
Expand All @@ -293,39 +320,81 @@ 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() {
3 => {
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;
Expand Down Expand Up @@ -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";
Expand All @@ -418,6 +495,8 @@ names! {
BMP, "bmp";
GIF, "gif";
JPEG, "jpeg";
WEBP, "webp";
AVIF, "avif";
PNG, "png";
SVG, "svg+xml";

Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -475,4 +583,3 @@ mimes! {
VIDEO_STAR, "video/*", 5;
AUDIO_STAR, "audio/*", 5;
}

Loading