3 HTTP protocol implementation for LuCI - mime handling
4 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
10 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.http.protocol.mime", package.seeall)
23 ["txt"] = "text/plain";
24 ["js"] = "text/javascript";
26 ["htm"] = "text/html";
27 ["html"] = "text/html";
29 ["gif"] = "image/gif";
30 ["png"] = "image/png";
31 ["jpg"] = "image/jpeg";
32 ["jpeg"] = "image/jpeg";
34 ["xml"] = "application/xml";
37 -- extract extension from a filename and return corresponding mime-type or
38 -- "application/octet-stream" if the extension is unknown
39 function to_mime(filename)
40 if type(filename) == "string" then
41 local ext = filename:match("[^%.]+$")
43 if ext and MIME_TYPES[ext:lower()] then
44 return MIME_TYPES[ext:lower()]
48 return "application/octet-stream"
51 -- return corresponding extension for a given mime type or nil if the
52 -- given mime-type is unknown
53 function to_ext(mimetype)
54 if type(mimetype) == "string" then
55 for ext, type in luci.util.kspairs( MIME_TYPES ) do
56 if type == mimetype then