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)
20 ["txt"] = "text/plain";
21 ["js"] = "text/javascript";
23 ["htm"] = "text/html";
24 ["html"] = "text/html";
26 ["gif"] = "image/gif";
27 ["png"] = "image/png";
28 ["jpg"] = "image/jpeg";
29 ["jpeg"] = "image/jpeg";
31 ["xml"] = "application/xml";
34 -- extract extension from a filename and return corresponding mime-type or
35 -- "application/octet-stream" if the extension is unknown
36 function to_mime(filename)
37 if type(filename) == "string" then
38 local ext = filename:match("[^%.]+$")
40 if ext and MIME_TYPES[ext:lower()] then
41 return MIME_TYPES[ext:lower()]
45 return "application/octet-stream"
48 -- return corresponding extension for a given mime type or nil if the
49 -- given mime-type is unknown
50 function to_ext(mimetype)
51 if type(mimetype) == "string" then
52 for ext, type in luci.util.kspairs( MIME_TYPES ) do
53 if type == mimetype then