Created
June 22, 2012 06:22
-
-
Save shiweifu/2970764 to your computer and use it in GitHub Desktop.
lua static webserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mime = {} | |
local mime_table = | |
{ | |
[".html"] = { | |
["mime"] = "text/html", | |
["bin"] = false | |
}, | |
[".xml"] = { | |
["mime"] = "application/xml", | |
["bin"] = false | |
}, | |
[".txt"] = { | |
["mime"] = "text/plain", | |
["bin"] = false | |
}, | |
[".css"] = { | |
["mime"] = "text/css", | |
["bin"] = false | |
}, | |
[".gif"] = { | |
["mime"] = "image/gif", | |
["bin"] = true | |
}, | |
[".jpg"] = { | |
["mime"] = "image/jpeg", | |
["bin"] = true | |
}, | |
[".png"] = { | |
["mime"] = "image/png", | |
["bin"] = true | |
}, | |
[".zip"] = { | |
["mime"] = "application/zip", | |
["bin"] = true | |
} | |
} | |
-- determine mime type based on file extension | |
function mime.getMime(ext) | |
for k,v in pairs(mime_table) do | |
if string.match(k, ext) then | |
return v.mime, v.bin | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment