Skip to content

Instantly share code, notes, and snippets.

@shiweifu
Created June 22, 2012 06:22
Show Gist options
  • Save shiweifu/2970764 to your computer and use it in GitHub Desktop.
Save shiweifu/2970764 to your computer and use it in GitHub Desktop.
lua static webserver
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