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

Add additional content types #465

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
211 changes: 166 additions & 45 deletions API/Protocol/ContentType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System;
using System.Linq;

namespace GenHTTP.Api.Protocol
{
Expand Down Expand Up @@ -108,26 +108,6 @@ public enum ContentType
/// </summary>
TextJavaScript,

/// <summary>
/// A H.264 encoded video file.
/// </summary>
VideoH264,

/// <summary>
/// A MP4 video file.
/// </summary>
VideoMp4,

/// <summary>
/// A MPEG video file.
/// </summary>
VideoMpeg,

/// <summary>
/// A MPEG-4 video file.
/// </summary>
VideoMpeg4Generic,

/// <summary>
/// A uncompressed audio file.
/// </summary>
Expand Down Expand Up @@ -206,7 +186,128 @@ public enum ContentType
/// <summary>
/// A Protobuf message.
/// </summary>
ApplicationProtobuf
ApplicationProtobuf,

/// <summary>
/// 3GPP video file container (.3gp).
/// </summary>
Video3Gpp,

/// <summary>
/// 3GPP2 video files (.3g2).
/// </summary>
Video3Gpp2,

/// <summary>
/// AV1 video file (.av1).
/// </summary>
VideoAV1,

/// <summary>
/// A MPEG4 Part 10 (H.264) video file (.avc).
/// </summary>
VideoAvc,

/// <summary>
/// Digital video file (.dv).
/// </summary>
VideoDV,

/// <summary>
/// A H.261 video file.
/// </summary>
VideoH261,

/// <summary>
/// A H.263 video file.
/// </summary>
VideoH263,

/// <summary>
/// A H.264 encoded video file.
/// </summary>
VideoH264,

/// <summary>
/// A H.265 video file.
/// </summary>
VideoH265,

/// <summary>
/// A H.266 video file.
/// </summary>
VideoH266,

/// <summary>
/// A Matroska video file (.mkv).
/// </summary>
VideoMatroska,

/// <summary>
/// A 3D Matroska video file (.mk3d).
/// </summary>
VideoMatroska3D,

/// <summary>
/// A Motion JPEG 2000 video file (.mj2).
/// </summary>
VideoMJ2,

/// <summary>
/// A MP4 video file (.mp4).
/// </summary>
VideoMP4,

/// <summary>
/// A MPEG video file.
/// </summary>
VideoMpeg,

/// <summary>
/// A MPEG-4 video file.
/// </summary>
VideoMpeg4Generic,

/// <summary>
/// A MPEG-2 elementary stream video (.mpv).
/// </summary>
VideoMpv,

/// <summary>
/// An Apple quick time video file (.mov or .hdmov).
/// </summary>
VideoQuicktime,

/// <summary>
/// A raw video file.
/// </summary>
VideoRaw,

/// <summary>
/// A SMPTE 421M video file (.vc1).
/// </summary>
VideoVC1,

/// <summary>
/// A SMPTE VC-2 video file.
/// </summary>
VideoVC2,

/// <summary>
/// A VP8 encoded video file (.webm).
/// </summary>
VideoVP8,

/// <summary>
/// A VP9 encoded video file (.webm).
/// </summary>
VideoVP9,

/// <summary>
/// A WebM video file (.webm).
/// </summary>
VideoWebM

}

#endregion
Expand Down Expand Up @@ -241,47 +342,67 @@ public class FlexibleContentType

#region Mapping

private static readonly Dictionary<ContentType, string> MAPPING = new()
private static readonly Dictionary<ContentType, string> 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<string, ContentType> MAPPING_REVERSE = MAPPING.ToDictionary(x => x.Value, x => x.Key);
Expand Down
18 changes: 17 additions & 1 deletion Modules/Basics/CoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 }
};

Expand Down
27 changes: 27 additions & 0 deletions Testing/Acceptance/Engine/ContentTypeTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

}