mod_http_upload: Guess mime type from file extension if not provided by client (mime-type is OPTIONAL)
--- a/mod_http_upload/mod_http_upload.lua Sat Apr 15 15:55:39 2017 +0200
+++ b/mod_http_upload/mod_http_upload.lua Sun Apr 16 00:58:02 2017 +0200
@@ -143,9 +143,16 @@
if mime_map then
local file_ext = filename:match("%.([^.]+)$");
- if (not file_ext and mimetype ~= "application/octet-stream") or (file_ext and mime_map[file_ext] ~= mimetype) then
- origin.send(st.error_reply(stanza, "modify", "bad-request", "MIME type does not match file extension"));
- return true;
+ if not mimetype then
+ mimetype = "application/octet-stream";
+ if file_ext then
+ mimetype = mime_map[file_ext] or mimetype;
+ end
+ else
+ if (not file_ext and mimetype ~= "application/octet-stream") or (file_ext and mime_map[file_ext] ~= mimetype) then
+ origin.send(st.error_reply(stanza, "modify", "bad-request", "MIME type does not match file extension"));
+ return true;
+ end
end
end