diff --git a/API/Protocol/ContentType.cs b/API/Protocol/ContentType.cs index 65e134fa..50cd83c9 100644 --- a/API/Protocol/ContentType.cs +++ b/API/Protocol/ContentType.cs @@ -1,6 +1,6 @@ -using System.Linq; +using System; using System.Collections.Generic; -using System; +using System.Linq; namespace GenHTTP.Api.Protocol { @@ -108,26 +108,6 @@ public enum ContentType /// TextJavaScript, - /// - /// A H.264 encoded video file. - /// - VideoH264, - - /// - /// A MP4 video file. - /// - VideoMp4, - - /// - /// A MPEG video file. - /// - VideoMpeg, - - /// - /// A MPEG-4 video file. - /// - VideoMpeg4Generic, - /// /// A uncompressed audio file. /// @@ -206,7 +186,128 @@ public enum ContentType /// /// A Protobuf message. /// - ApplicationProtobuf + ApplicationProtobuf, + + /// + /// 3GPP video file container (.3gp). + /// + Video3Gpp, + + /// + /// 3GPP2 video files (.3g2). + /// + Video3Gpp2, + + /// + /// AV1 video file (.av1). + /// + VideoAV1, + + /// + /// A MPEG4 Part 10 (H.264) video file (.avc). + /// + VideoAvc, + + /// + /// Digital video file (.dv). + /// + VideoDV, + + /// + /// A H.261 video file. + /// + VideoH261, + + /// + /// A H.263 video file. + /// + VideoH263, + + /// + /// A H.264 encoded video file. + /// + VideoH264, + + /// + /// A H.265 video file. + /// + VideoH265, + + /// + /// A H.266 video file. + /// + VideoH266, + + /// + /// A Matroska video file (.mkv). + /// + VideoMatroska, + + /// + /// A 3D Matroska video file (.mk3d). + /// + VideoMatroska3D, + + /// + /// A Motion JPEG 2000 video file (.mj2). + /// + VideoMJ2, + + /// + /// A MP4 video file (.mp4). + /// + VideoMP4, + + /// + /// A MPEG video file. + /// + VideoMpeg, + + /// + /// A MPEG-4 video file. + /// + VideoMpeg4Generic, + + /// + /// A MPEG-2 elementary stream video (.mpv). + /// + VideoMpv, + + /// + /// An Apple quick time video file (.mov or .hdmov). + /// + VideoQuicktime, + + /// + /// A raw video file. + /// + VideoRaw, + + /// + /// A SMPTE 421M video file (.vc1). + /// + VideoVC1, + + /// + /// A SMPTE VC-2 video file. + /// + VideoVC2, + + /// + /// A VP8 encoded video file (.webm). + /// + VideoVP8, + + /// + /// A VP9 encoded video file (.webm). + /// + VideoVP9, + + /// + /// A WebM video file (.webm). + /// + VideoWebM + } #endregion @@ -241,47 +342,67 @@ public class FlexibleContentType #region Mapping - private static readonly Dictionary MAPPING = new() + private static readonly Dictionary MAPPING = new() { - { ContentType.TextHtml, "text/html" }, - { ContentType.TextCss, "text/css" }, - { ContentType.ApplicationJavaScript, "application/javascript" }, - { ContentType.ImageIcon, "image/x-icon" }, - { ContentType.ImageGif, "image/gif" }, - { ContentType.ImageJpg, "image/jpg" }, - { ContentType.ImagePng, "image/png" }, - { ContentType.ImageBmp, "image/bmp" }, { ContentType.AudioMp4, "audio/mp4" }, { ContentType.AudioOgg, "audio/ogg" }, { ContentType.AudioMpeg, "audio/mpeg" }, - { ContentType.ImageTiff, "image/tiff" }, - { ContentType.TextCsv, "text/csv" }, - { ContentType.TextRichText, "text/richtext" }, - { ContentType.TextPlain, "text/plain" }, - { ContentType.TextJavaScript, "text/javascript" }, - { ContentType.TextXml, "text/xml" }, - { ContentType.VideoH264, "video/H264" }, - { ContentType.VideoMp4, "video/mp4" }, - { ContentType.VideoMpeg, "video/mpeg" }, - { ContentType.VideoMpeg4Generic, "video/mpeg4-generic" }, { ContentType.AudioWav, "audio/wav" }, + { ContentType.ApplicationJavaScript, "application/javascript" }, { ContentType.ApplicationOfficeDocumentWordProcessing, "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, { ContentType.ApplicationOfficeDocumentPresentation, "application/vnd.openxmlformats-officedocument.presentationml.presentation" }, { ContentType.ApplicationOfficeDocumentSlideshow, "application/vnd.openxmlformats-officedocument.presentationml.slideshow" }, { ContentType.ApplicationOfficeDocumentSheet, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, { ContentType.ApplicationForceDownload, "application/force-download" }, { ContentType.ApplicationOctetStream, "application/octet-stream" }, + { ContentType.ApplicationJson, "application/json" }, + { ContentType.ApplicationWwwFormUrlEncoded, "application/x-www-form-urlencoded" }, + { ContentType.ApplicationProtobuf, "application/protobuf" }, { ContentType.FontEmbeddedOpenTypeFont, "font/eot" }, { ContentType.FontOpenTypeFont, "font/otf" }, { ContentType.FontTrueTypeFont, "font/ttf" }, { ContentType.FontWoff, "font/woff" }, { ContentType.FontWoff2, "font/woff2" }, + { ContentType.ImageIcon, "image/x-icon" }, + { ContentType.ImageGif, "image/gif" }, + { ContentType.ImageJpg, "image/jpg" }, + { ContentType.ImagePng, "image/png" }, + { ContentType.ImageTiff, "image/tiff" }, + { ContentType.ImageBmp, "image/bmp" }, { ContentType.ImageScalableVectorGraphics, "image/svg" }, { ContentType.ImageScalableVectorGraphicsXml, "image/svg+xml" }, { ContentType.ImageScalableVectorGraphicsCompressed, "image/svgz" }, - { ContentType.ApplicationJson, "application/json" }, - { ContentType.ApplicationWwwFormUrlEncoded, "application/x-www-form-urlencoded" }, - { ContentType.ApplicationProtobuf, "application/protobuf" } + { ContentType.TextHtml, "text/html" }, + { ContentType.TextCss, "text/css" }, + { ContentType.TextCsv, "text/csv" }, + { ContentType.TextRichText, "text/richtext" }, + { ContentType.TextPlain, "text/plain" }, + { ContentType.TextJavaScript, "text/javascript" }, + { ContentType.TextXml, "text/xml" }, + { ContentType.Video3Gpp, "video/3gpp" }, + { ContentType.Video3Gpp2, "video/3gpp2" }, + { ContentType.VideoAV1, "video/av1" }, + { ContentType.VideoAvc, "video/av" }, + { ContentType.VideoDV, "video/dv" }, + { ContentType.VideoH261, "video/H261" }, + { ContentType.VideoH263, "video/H263" }, + { ContentType.VideoH264, "video/H264" }, + { ContentType.VideoH265, "video/H265" }, + { ContentType.VideoH266, "video/H266" }, + { ContentType.VideoMatroska, "video/matroska" }, + { ContentType.VideoMatroska3D, "video/matroska-3d" }, + { ContentType.VideoMJ2, "video/mj2" }, + { ContentType.VideoMP4, "video/mp4" }, + { ContentType.VideoMpeg, "video/mpeg" }, + { ContentType.VideoMpeg4Generic, "video/mpeg4-generic" }, + { ContentType.VideoMpv, "video/MPV" }, + { ContentType.VideoQuicktime, "video/quicktime" }, + { ContentType.VideoRaw, "video/raw" }, + { ContentType.VideoVC1, "video/vc1" }, + { ContentType.VideoVC2, "video/vc2" }, + { ContentType.VideoVP8, "video/VP8" }, + { ContentType.VideoVP9, "video/VP9" }, + { ContentType.VideoWebM, "video/webm" } }; private static readonly Dictionary MAPPING_REVERSE = MAPPING.ToDictionary(x => x.Value, x => x.Key); diff --git a/Modules/Basics/CoreExtensions.cs b/Modules/Basics/CoreExtensions.cs index 5a9e0d1b..0dae84fb 100644 --- a/Modules/Basics/CoreExtensions.cs +++ b/Modules/Basics/CoreExtensions.cs @@ -104,9 +104,24 @@ public static bool HasType(this IRequest request, params RequestMethod[] methods { "mp3", ContentType.AudioMpeg }, { "wav", ContentType.AudioWav }, // Video + { "avi", ContentType.VideoMpeg }, + { "3gp", ContentType.Video3Gpp }, + { "3g2", ContentType.Video3Gpp2 }, + { "av1", ContentType.VideoAV1 }, + { "avc", ContentType.VideoAvc }, + { "dv", ContentType.VideoDV }, + { "mkv", ContentType.VideoMatroska }, + { "mk3d", ContentType.VideoMatroska3D }, + { "mj2", ContentType.VideoMJ2 }, { "mpg", ContentType.VideoMpeg }, + { "mp4", ContentType.VideoMP4 }, { "mpeg", ContentType.VideoMpeg }, - { "avi", ContentType.VideoMpeg }, + { "mpv", ContentType.VideoMpv }, + { "mov", ContentType.VideoQuicktime }, + { "hdmov", ContentType.VideoQuicktime }, + { "vc1", ContentType.VideoVC1 }, + { "vc2", ContentType.VideoVC2 }, + { "webm", ContentType.VideoWebM }, // Documents { "csv", ContentType.TextCsv }, { "rtf", ContentType.TextRichText }, @@ -115,6 +130,7 @@ public static bool HasType(this IRequest request, params RequestMethod[] methods { "ppsx", ContentType.ApplicationOfficeDocumentSlideshow }, { "xslx", ContentType.ApplicationOfficeDocumentSheet }, // Object models + { "json", ContentType.ApplicationJson }, { "xml", ContentType.TextXml } }; diff --git a/Testing/Acceptance/Engine/ContentTypeTests.cs b/Testing/Acceptance/Engine/ContentTypeTests.cs new file mode 100644 index 00000000..4cd4110d --- /dev/null +++ b/Testing/Acceptance/Engine/ContentTypeTests.cs @@ -0,0 +1,27 @@ +using System; + +using GenHTTP.Api.Protocol; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace GenHTTP.Testing.Acceptance.Engine +{ + + [TestClass] + public sealed class ContentTypeTests + { + + [TestMethod] + public void MapContentTypeTests() + { + foreach (ContentType contentType in Enum.GetValues(typeof(ContentType))) + { + var mapped = new FlexibleContentType(contentType); + + Assert.AreEqual(mapped.KnownType, contentType); + } + } + + } + +}