Software /
code /
prosody-modules
Diff
mod_http_upload/mod_http_upload.lua @ 3625:a578b4977bb0
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 29 Jun 2019 19:26:08 +0200 |
parent | 3590:d8cc8b71a199 |
child | 3648:aa12b95a6d36 |
line wrap: on
line diff
--- 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);