Skip to content

Commit 0481eae

Browse files
Add additional content types (#465)
* Add content types for typical video formats * Fix .mp4 detection to video/mp4
1 parent 8ea2994 commit 0481eae

File tree

3 files changed

+210
-46
lines changed

3 files changed

+210
-46
lines changed

API/Protocol/ContentType.cs

+166-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Linq;
1+
using System;
22
using System.Collections.Generic;
3-
using System;
3+
using System.Linq;
44

55
namespace GenHTTP.Api.Protocol
66
{
@@ -108,26 +108,6 @@ public enum ContentType
108108
/// </summary>
109109
TextJavaScript,
110110

111-
/// <summary>
112-
/// A H.264 encoded video file.
113-
/// </summary>
114-
VideoH264,
115-
116-
/// <summary>
117-
/// A MP4 video file.
118-
/// </summary>
119-
VideoMp4,
120-
121-
/// <summary>
122-
/// A MPEG video file.
123-
/// </summary>
124-
VideoMpeg,
125-
126-
/// <summary>
127-
/// A MPEG-4 video file.
128-
/// </summary>
129-
VideoMpeg4Generic,
130-
131111
/// <summary>
132112
/// A uncompressed audio file.
133113
/// </summary>
@@ -206,7 +186,128 @@ public enum ContentType
206186
/// <summary>
207187
/// A Protobuf message.
208188
/// </summary>
209-
ApplicationProtobuf
189+
ApplicationProtobuf,
190+
191+
/// <summary>
192+
/// 3GPP video file container (.3gp).
193+
/// </summary>
194+
Video3Gpp,
195+
196+
/// <summary>
197+
/// 3GPP2 video files (.3g2).
198+
/// </summary>
199+
Video3Gpp2,
200+
201+
/// <summary>
202+
/// AV1 video file (.av1).
203+
/// </summary>
204+
VideoAV1,
205+
206+
/// <summary>
207+
/// A MPEG4 Part 10 (H.264) video file (.avc).
208+
/// </summary>
209+
VideoAvc,
210+
211+
/// <summary>
212+
/// Digital video file (.dv).
213+
/// </summary>
214+
VideoDV,
215+
216+
/// <summary>
217+
/// A H.261 video file.
218+
/// </summary>
219+
VideoH261,
220+
221+
/// <summary>
222+
/// A H.263 video file.
223+
/// </summary>
224+
VideoH263,
225+
226+
/// <summary>
227+
/// A H.264 encoded video file.
228+
/// </summary>
229+
VideoH264,
230+
231+
/// <summary>
232+
/// A H.265 video file.
233+
/// </summary>
234+
VideoH265,
235+
236+
/// <summary>
237+
/// A H.266 video file.
238+
/// </summary>
239+
VideoH266,
240+
241+
/// <summary>
242+
/// A Matroska video file (.mkv).
243+
/// </summary>
244+
VideoMatroska,
245+
246+
/// <summary>
247+
/// A 3D Matroska video file (.mk3d).
248+
/// </summary>
249+
VideoMatroska3D,
250+
251+
/// <summary>
252+
/// A Motion JPEG 2000 video file (.mj2).
253+
/// </summary>
254+
VideoMJ2,
255+
256+
/// <summary>
257+
/// A MP4 video file (.mp4).
258+
/// </summary>
259+
VideoMP4,
260+
261+
/// <summary>
262+
/// A MPEG video file.
263+
/// </summary>
264+
VideoMpeg,
265+
266+
/// <summary>
267+
/// A MPEG-4 video file.
268+
/// </summary>
269+
VideoMpeg4Generic,
270+
271+
/// <summary>
272+
/// A MPEG-2 elementary stream video (.mpv).
273+
/// </summary>
274+
VideoMpv,
275+
276+
/// <summary>
277+
/// An Apple quick time video file (.mov or .hdmov).
278+
/// </summary>
279+
VideoQuicktime,
280+
281+
/// <summary>
282+
/// A raw video file.
283+
/// </summary>
284+
VideoRaw,
285+
286+
/// <summary>
287+
/// A SMPTE 421M video file (.vc1).
288+
/// </summary>
289+
VideoVC1,
290+
291+
/// <summary>
292+
/// A SMPTE VC-2 video file.
293+
/// </summary>
294+
VideoVC2,
295+
296+
/// <summary>
297+
/// A VP8 encoded video file (.webm).
298+
/// </summary>
299+
VideoVP8,
300+
301+
/// <summary>
302+
/// A VP9 encoded video file (.webm).
303+
/// </summary>
304+
VideoVP9,
305+
306+
/// <summary>
307+
/// A WebM video file (.webm).
308+
/// </summary>
309+
VideoWebM
310+
210311
}
211312

212313
#endregion
@@ -241,47 +342,67 @@ public class FlexibleContentType
241342

242343
#region Mapping
243344

244-
private static readonly Dictionary<ContentType, string> MAPPING = new()
345+
private static readonly Dictionary<ContentType, string> MAPPING = new()
245346
{
246-
{ ContentType.TextHtml, "text/html" },
247-
{ ContentType.TextCss, "text/css" },
248-
{ ContentType.ApplicationJavaScript, "application/javascript" },
249-
{ ContentType.ImageIcon, "image/x-icon" },
250-
{ ContentType.ImageGif, "image/gif" },
251-
{ ContentType.ImageJpg, "image/jpg" },
252-
{ ContentType.ImagePng, "image/png" },
253-
{ ContentType.ImageBmp, "image/bmp" },
254347
{ ContentType.AudioMp4, "audio/mp4" },
255348
{ ContentType.AudioOgg, "audio/ogg" },
256349
{ ContentType.AudioMpeg, "audio/mpeg" },
257-
{ ContentType.ImageTiff, "image/tiff" },
258-
{ ContentType.TextCsv, "text/csv" },
259-
{ ContentType.TextRichText, "text/richtext" },
260-
{ ContentType.TextPlain, "text/plain" },
261-
{ ContentType.TextJavaScript, "text/javascript" },
262-
{ ContentType.TextXml, "text/xml" },
263-
{ ContentType.VideoH264, "video/H264" },
264-
{ ContentType.VideoMp4, "video/mp4" },
265-
{ ContentType.VideoMpeg, "video/mpeg" },
266-
{ ContentType.VideoMpeg4Generic, "video/mpeg4-generic" },
267350
{ ContentType.AudioWav, "audio/wav" },
351+
{ ContentType.ApplicationJavaScript, "application/javascript" },
268352
{ ContentType.ApplicationOfficeDocumentWordProcessing, "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
269353
{ ContentType.ApplicationOfficeDocumentPresentation, "application/vnd.openxmlformats-officedocument.presentationml.presentation" },
270354
{ ContentType.ApplicationOfficeDocumentSlideshow, "application/vnd.openxmlformats-officedocument.presentationml.slideshow" },
271355
{ ContentType.ApplicationOfficeDocumentSheet, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
272356
{ ContentType.ApplicationForceDownload, "application/force-download" },
273357
{ ContentType.ApplicationOctetStream, "application/octet-stream" },
358+
{ ContentType.ApplicationJson, "application/json" },
359+
{ ContentType.ApplicationWwwFormUrlEncoded, "application/x-www-form-urlencoded" },
360+
{ ContentType.ApplicationProtobuf, "application/protobuf" },
274361
{ ContentType.FontEmbeddedOpenTypeFont, "font/eot" },
275362
{ ContentType.FontOpenTypeFont, "font/otf" },
276363
{ ContentType.FontTrueTypeFont, "font/ttf" },
277364
{ ContentType.FontWoff, "font/woff" },
278365
{ ContentType.FontWoff2, "font/woff2" },
366+
{ ContentType.ImageIcon, "image/x-icon" },
367+
{ ContentType.ImageGif, "image/gif" },
368+
{ ContentType.ImageJpg, "image/jpg" },
369+
{ ContentType.ImagePng, "image/png" },
370+
{ ContentType.ImageTiff, "image/tiff" },
371+
{ ContentType.ImageBmp, "image/bmp" },
279372
{ ContentType.ImageScalableVectorGraphics, "image/svg" },
280373
{ ContentType.ImageScalableVectorGraphicsXml, "image/svg+xml" },
281374
{ ContentType.ImageScalableVectorGraphicsCompressed, "image/svgz" },
282-
{ ContentType.ApplicationJson, "application/json" },
283-
{ ContentType.ApplicationWwwFormUrlEncoded, "application/x-www-form-urlencoded" },
284-
{ ContentType.ApplicationProtobuf, "application/protobuf" }
375+
{ ContentType.TextHtml, "text/html" },
376+
{ ContentType.TextCss, "text/css" },
377+
{ ContentType.TextCsv, "text/csv" },
378+
{ ContentType.TextRichText, "text/richtext" },
379+
{ ContentType.TextPlain, "text/plain" },
380+
{ ContentType.TextJavaScript, "text/javascript" },
381+
{ ContentType.TextXml, "text/xml" },
382+
{ ContentType.Video3Gpp, "video/3gpp" },
383+
{ ContentType.Video3Gpp2, "video/3gpp2" },
384+
{ ContentType.VideoAV1, "video/av1" },
385+
{ ContentType.VideoAvc, "video/av" },
386+
{ ContentType.VideoDV, "video/dv" },
387+
{ ContentType.VideoH261, "video/H261" },
388+
{ ContentType.VideoH263, "video/H263" },
389+
{ ContentType.VideoH264, "video/H264" },
390+
{ ContentType.VideoH265, "video/H265" },
391+
{ ContentType.VideoH266, "video/H266" },
392+
{ ContentType.VideoMatroska, "video/matroska" },
393+
{ ContentType.VideoMatroska3D, "video/matroska-3d" },
394+
{ ContentType.VideoMJ2, "video/mj2" },
395+
{ ContentType.VideoMP4, "video/mp4" },
396+
{ ContentType.VideoMpeg, "video/mpeg" },
397+
{ ContentType.VideoMpeg4Generic, "video/mpeg4-generic" },
398+
{ ContentType.VideoMpv, "video/MPV" },
399+
{ ContentType.VideoQuicktime, "video/quicktime" },
400+
{ ContentType.VideoRaw, "video/raw" },
401+
{ ContentType.VideoVC1, "video/vc1" },
402+
{ ContentType.VideoVC2, "video/vc2" },
403+
{ ContentType.VideoVP8, "video/VP8" },
404+
{ ContentType.VideoVP9, "video/VP9" },
405+
{ ContentType.VideoWebM, "video/webm" }
285406
};
286407

287408
private static readonly Dictionary<string, ContentType> MAPPING_REVERSE = MAPPING.ToDictionary(x => x.Value, x => x.Key);

Modules/Basics/CoreExtensions.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,24 @@ public static bool HasType(this IRequest request, params RequestMethod[] methods
104104
{ "mp3", ContentType.AudioMpeg },
105105
{ "wav", ContentType.AudioWav },
106106
// Video
107+
{ "avi", ContentType.VideoMpeg },
108+
{ "3gp", ContentType.Video3Gpp },
109+
{ "3g2", ContentType.Video3Gpp2 },
110+
{ "av1", ContentType.VideoAV1 },
111+
{ "avc", ContentType.VideoAvc },
112+
{ "dv", ContentType.VideoDV },
113+
{ "mkv", ContentType.VideoMatroska },
114+
{ "mk3d", ContentType.VideoMatroska3D },
115+
{ "mj2", ContentType.VideoMJ2 },
107116
{ "mpg", ContentType.VideoMpeg },
117+
{ "mp4", ContentType.VideoMP4 },
108118
{ "mpeg", ContentType.VideoMpeg },
109-
{ "avi", ContentType.VideoMpeg },
119+
{ "mpv", ContentType.VideoMpv },
120+
{ "mov", ContentType.VideoQuicktime },
121+
{ "hdmov", ContentType.VideoQuicktime },
122+
{ "vc1", ContentType.VideoVC1 },
123+
{ "vc2", ContentType.VideoVC2 },
124+
{ "webm", ContentType.VideoWebM },
110125
// Documents
111126
{ "csv", ContentType.TextCsv },
112127
{ "rtf", ContentType.TextRichText },
@@ -115,6 +130,7 @@ public static bool HasType(this IRequest request, params RequestMethod[] methods
115130
{ "ppsx", ContentType.ApplicationOfficeDocumentSlideshow },
116131
{ "xslx", ContentType.ApplicationOfficeDocumentSheet },
117132
// Object models
133+
{ "json", ContentType.ApplicationJson },
118134
{ "xml", ContentType.TextXml }
119135
};
120136

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
using GenHTTP.Api.Protocol;
4+
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
namespace GenHTTP.Testing.Acceptance.Engine
8+
{
9+
10+
[TestClass]
11+
public sealed class ContentTypeTests
12+
{
13+
14+
[TestMethod]
15+
public void MapContentTypeTests()
16+
{
17+
foreach (ContentType contentType in Enum.GetValues(typeof(ContentType)))
18+
{
19+
var mapped = new FlexibleContentType(contentType);
20+
21+
Assert.AreEqual(mapped.KnownType, contentType);
22+
}
23+
}
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)