# HG changeset patch # User Kim Alvefur # Date 1561829168 -7200 # Node ID a578b4977bb09901febef1abd5c66a7e7c933a4e # Parent 3109a65ab7f4f49ba833876c6c7f16ce0ce131d3 mod_http_upload: Duplicate mime types handling from mod_http_files (fixes #1374) When using net.http.files this isn't automatically provided via mod_http_files so we need to do it ourselves. diff -r 3109a65ab7f4 -r a578b4977bb0 mod_http_upload/mod_http_upload.lua --- a/mod_http_upload/mod_http_upload.lua Wed Jun 26 21:45:50 2019 +0200 +++ b/mod_http_upload/mod_http_upload.lua Sat Jun 29 19:26:08 2019 +0200 @@ -52,6 +52,35 @@ http_files = module:depends"http_files"; end +local mime_map = module:shared("/*/http_files/mime").types; +if not mime_map then + mime_map = { + html = "text/html", htm = "text/html", + xml = "application/xml", + txt = "text/plain", + css = "text/css", + js = "application/javascript", + png = "image/png", + gif = "image/gif", + jpeg = "image/jpeg", jpg = "image/jpeg", + svg = "image/svg+xml", + }; + module:shared("/*/http_files/mime").types = mime_map; + + local mime_types, err = io.open(module:get_option_path("mime_types_file", "/etc/mime.types", "config"), "r"); + if mime_types then + local mime_data = mime_types:read("*a"); + mime_types:close(); + setmetatable(mime_map, { + __index = function(t, ext) + local typ = mime_data:match("\n(%S+)[^\n]*%s"..(ext:lower()).."%s") or "application/octet-stream"; + t[ext] = typ; + return typ; + end + }); + end +end + -- namespaces local namespace = "urn:xmpp:http:upload:0"; local legacy_namespace = "urn:xmpp:http:upload"; @@ -342,7 +371,7 @@ end end -local serve_uploaded_files = http_files.serve(storage_path); +local serve_uploaded_files = http_files.serve({ path = storage_path, mime_map = mime_map }); local function serve_head(event, path) set_cross_domain_headers(event.response);