admin
2020-06-10 a610f2ab6e543d2cb78c1ef212ac6a74ddc067d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
 
 
using System;
using System.Collections.Generic;
 
namespace CefSharp.Internals
{
    /// <summary>
    /// Internal Mime Type Mappings.
    /// </summary>
    public static class MimeTypeMapping
    {
        /// <summary>
        /// Dictionary containing our custom mimeType mapping, you can add your own file extension
        /// to mimeType mappings to this dictionary.
        /// </summary>
        public static readonly IDictionary<string, string> CustomMappings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
        {
            // Recently added entries from 
            // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
            // https://cs.chromium.org/chromium/src/net/base/mime_util.cc?sq=package:chromium&g=0&l=147
            // https://www.w3.org/TR/WOFF2/#IMT
            // https://tools.ietf.org/html/rfc8081#section-4.4.6
            {"woff2", "font/woff2"},
            {"ttf", "font/ttf"},
            {"otf", "font/otf"}
        };
 
        /// <summary>
        /// Lookup MimeType from the <see cref="CustomMappings"/>
        /// dictionary based on file extension.
        /// </summary>
        /// <param name="extension">extension</param>
        /// <returns>custom mimeType or application/octet-stream if no mapping found </returns>
        public static string GetCustomMapping(string extension)
        {
            string mime;
            return CustomMappings.TryGetValue(extension, out mime) ? mime : "application/octet-stream";
        }
    }
}