nit: Added link to `CONTRIBUTING.md` from the README
[nit.git] / lib / nitcorn / media_types.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2013 Justin Michaud-Ouellette
4 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 # Services to identify Internet media types (or MIME types, Content-types)
19 module media_types
20
21 # Map of known MIME types
22 class MediaTypes
23 protected var types = new HashMap[String, String]
24
25 # Get the type/subtype associated to a file extension `ext`
26 fun [](ext: String): nullable String
27 do
28 if types.keys.has(ext) then return types[ext]
29 return null
30 end
31
32 init
33 do
34 types["html"] = "text/html"
35 types["htm"] = "text/html"
36 types["shtml"] = "text/html"
37 types["css"] = "text/css"
38 types["xml"] = "text/xml"
39 types["rss"] = "text/xml"
40 types["gif"] = "image/gif"
41 types["jpg"] = "image/jpeg"
42 types["jpeg"] = "image/jpeg"
43 types["js"] = "application/x-javascript"
44 types["txt"] = "text/plain"
45 types["htc"] = "text/x-component"
46 types["mml"] = "text/mathml"
47 types["png"] = "image/png"
48 types["ico"] = "image/x-icon"
49 types["jng"] = "image/x-jng"
50 types["wbmp"] = "image/vnd.wap.wbmp"
51 types["jar"] = "application/java-archive"
52 types["war"] = "application/java-archive"
53 types["ear"] = "application/java-archive"
54 types["json"] = "application/json"
55 types["hqx"] = "application/mac-binhex40"
56 types["pdf"] = "application/pdf"
57 types["cco"] = "application/x-cocoa"
58 types["jardiff"] = "application/x-java-archive-diff"
59 types["jnlp"] = "application/x-java-jnlp-file"
60 types["run"] = "application/x-makeself"
61 types["pl"] = "application/x-perl"
62 types["pm"] = "application/x-perl"
63 types["pdb"] = "application/x-pilot"
64 types["prc"] = "application/x-pilot"
65 types["rar"] = "application/x-rar-compressed"
66 types["rpm"] = "application/x-redhat-package-manager"
67 types["sea"] = "application/x-sea"
68 types["swf"] = "application/x-shockwave-flash"
69 types["sit"] = "application/x-stuffit"
70 types["tcl"] = "application/x-tcl"
71 types["tk"] = "application/x-tcl"
72 types["der"] = "application/x-x509-ca-cert"
73 types["pem"] = "application/x-x509-ca-cert"
74 types["crt"] = "application/x-x509-ca-cert"
75 types["xpi"] = "application/x-xpinstall"
76 types["zip"] = "application/zip"
77 types["deb"] = "application/octet-stream"
78 types["bin"] = "application/octet-stream"
79 types["exe"] = "application/octet-stream"
80 types["dll"] = "application/octet-stream"
81 types["dmg"] = "application/octet-stream"
82 types["eot"] = "application/octet-stream"
83 types["iso"] = "application/octet-stream"
84 types["img"] = "application/octet-stream"
85 types["msi"] = "application/octet-stream"
86 types["msp"] = "application/octet-stream"
87 types["msm"] = "application/octet-stream"
88 types["mp3"] = "audio/mpeg"
89 types["ra"] = "audio/x-realaudio"
90 types["mpeg"] = "video/mpeg"
91 types["mpg"] = "video/mpeg"
92 types["mov"] = "video/quicktime"
93 types["flv"] = "video/x-flv"
94 types["avi"] = "video/x-msvideo"
95 types["wmv"] = "video/x-ms-wmv"
96 types["asx"] = "video/x-ms-asf"
97 types["asf"] = "video/x-ms-asf"
98 types["mng"] = "video/x-mng"
99 types["apk"] = "application/vnd.android.package-archive"
100 types["svg"] = "image/svg+xml"
101 types["ttf"] = "application/x-font-ttf"
102 types["otf"] = "application/x-font-opentype"
103 types["eof"] = "application/vnd.ms-fontobject"
104 types["woff"] = "application/font-woff"
105 types["woff2"] = "application/font-woff2"
106 end
107 end
108
109 fun media_types: MediaTypes do return once new MediaTypes