luci-lib-httpprotoutils: add airplay mime types
[project/luci.git] / libs / luci-lib-httpprotoutils / luasrc / http / mime.lua
1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 -- This class provides functions to guess mime types from file extensions and
5 -- vice versa.
6 module("luci.http.mime", package.seeall)
7
8 require("luci.util")
9
10 MIME_TYPES = {
11 ["txt"] = "text/plain";
12 ["js"] = "text/javascript";
13 ["css"] = "text/css";
14 ["htm"] = "text/html";
15 ["html"] = "text/html";
16 ["patch"] = "text/x-patch";
17 ["c"] = "text/x-csrc";
18 ["h"] = "text/x-chdr";
19 ["o"] = "text/x-object";
20 ["ko"] = "text/x-object";
21
22 ["bmp"] = "image/bmp";
23 ["gif"] = "image/gif";
24 ["png"] = "image/png";
25 ["jpg"] = "image/jpeg";
26 ["jpeg"] = "image/jpeg";
27 ["svg"] = "image/svg+xml";
28
29 ["zip"] = "application/zip";
30 ["pdf"] = "application/pdf";
31 ["xml"] = "application/xml";
32 ["xsl"] = "application/xml";
33 ["doc"] = "application/msword";
34 ["ppt"] = "application/vnd.ms-powerpoint";
35 ["xls"] = "application/vnd.ms-excel";
36 ["odt"] = "application/vnd.oasis.opendocument.text";
37 ["odp"] = "application/vnd.oasis.opendocument.presentation";
38 ["pl"] = "application/x-perl";
39 ["sh"] = "application/x-shellscript";
40 ["php"] = "application/x-php";
41 ["deb"] = "application/x-deb";
42 ["iso"] = "application/x-cd-image";
43 ["tgz"] = "application/x-compressed-tar";
44
45 ["mp3"] = "audio/mpeg";
46 ["ogg"] = "audio/x-vorbis+ogg";
47 ["wav"] = "audio/x-wav";
48 ["aac"] = "audio/aac";
49
50 ["mpg"] = "video/mpeg";
51 ["mpeg"] = "video/mpeg";
52 ["avi"] = "video/x-msvideo";
53 ["mov"] = "video/quicktime";
54 ["mp4"] = "video/mp4";
55 }
56
57 -- "application/octet-stream" if the extension is unknown.
58 function to_mime(filename)
59 if type(filename) == "string" then
60 local ext = filename:match("[^%.]+$")
61
62 if ext and MIME_TYPES[ext:lower()] then
63 return MIME_TYPES[ext:lower()]
64 end
65 end
66
67 return "application/octet-stream"
68 end
69
70 -- given mime-type is unknown.
71 function to_ext(mimetype)
72 if type(mimetype) == "string" then
73 for ext, type in luci.util.kspairs( MIME_TYPES ) do
74 if type == mimetype then
75 return ext
76 end
77 end
78 end
79
80 return nil
81 end