Merge: Added contributing guidelines and link from 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
24 # MIME types by extensions.
25 protected var types = new HashMap[String, String]
26
27 # Get the type/subtype associated to a file extension `ext`
28 fun [](ext: String): nullable String
29 do
30 if types.keys.has(ext) then return types[ext]
31 return null
32 end
33
34 init
35 do
36 types["html"] = "text/html"
37 types["htm"] = "text/html"
38 types["shtml"] = "text/html"
39 types["css"] = "text/css"
40 types["xml"] = "text/xml"
41 types["rss"] = "text/xml"
42 types["gif"] = "image/gif"
43 types["jpg"] = "image/jpeg"
44 types["jpeg"] = "image/jpeg"
45 types["js"] = "application/x-javascript"
46 types["txt"] = "text/plain"
47 types["htc"] = "text/x-component"
48 types["mml"] = "text/mathml"
49 types["png"] = "image/png"
50 types["ico"] = "image/x-icon"
51 types["jng"] = "image/x-jng"
52 types["wbmp"] = "image/vnd.wap.wbmp"
53 types["jar"] = "application/java-archive"
54 types["war"] = "application/java-archive"
55 types["ear"] = "application/java-archive"
56 types["json"] = "application/json"
57 types["hqx"] = "application/mac-binhex40"
58 types["pdf"] = "application/pdf"
59 types["cco"] = "application/x-cocoa"
60 types["jardiff"] = "application/x-java-archive-diff"
61 types["jnlp"] = "application/x-java-jnlp-file"
62 types["run"] = "application/x-makeself"
63 types["pl"] = "application/x-perl"
64 types["pm"] = "application/x-perl"
65 types["pdb"] = "application/x-pilot"
66 types["prc"] = "application/x-pilot"
67 types["rar"] = "application/x-rar-compressed"
68 types["rpm"] = "application/x-redhat-package-manager"
69 types["sea"] = "application/x-sea"
70 types["swf"] = "application/x-shockwave-flash"
71 types["sit"] = "application/x-stuffit"
72 types["tcl"] = "application/x-tcl"
73 types["tk"] = "application/x-tcl"
74 types["der"] = "application/x-x509-ca-cert"
75 types["pem"] = "application/x-x509-ca-cert"
76 types["crt"] = "application/x-x509-ca-cert"
77 types["xpi"] = "application/x-xpinstall"
78 types["zip"] = "application/zip"
79 types["deb"] = "application/octet-stream"
80 types["bin"] = "application/octet-stream"
81 types["exe"] = "application/octet-stream"
82 types["dll"] = "application/octet-stream"
83 types["dmg"] = "application/octet-stream"
84 types["eot"] = "application/octet-stream"
85 types["iso"] = "application/octet-stream"
86 types["img"] = "application/octet-stream"
87 types["msi"] = "application/octet-stream"
88 types["msp"] = "application/octet-stream"
89 types["msm"] = "application/octet-stream"
90 types["mp3"] = "audio/mpeg"
91 types["ra"] = "audio/x-realaudio"
92 types["mpeg"] = "video/mpeg"
93 types["mpg"] = "video/mpeg"
94 types["mov"] = "video/quicktime"
95 types["flv"] = "video/x-flv"
96 types["avi"] = "video/x-msvideo"
97 types["wmv"] = "video/x-ms-wmv"
98 types["asx"] = "video/x-ms-asf"
99 types["asf"] = "video/x-ms-asf"
100 types["mng"] = "video/x-mng"
101 types["apk"] = "application/vnd.android.package-archive"
102 types["svg"] = "image/svg+xml"
103 types["ttf"] = "application/x-font-ttf"
104 types["otf"] = "application/x-font-opentype"
105 types["eof"] = "application/vnd.ms-fontobject"
106 types["woff"] = "application/font-woff"
107 types["woff2"] = "application/font-woff2"
108 end
109 end
110
111 # MIME types list.
112 fun media_types: MediaTypes do return once new MediaTypes