# HG changeset patch # User Kim Alvefur # Date 1492297082 -7200 # Node ID 785465f8af3de6262a0332a0d4fdb1eca56dfdb5 # Parent 92ddfc548ce8131e77d634e8c1d3690841aedbe0 mod_http_upload: Guess mime type from file extension if not provided by client (mime-type is OPTIONAL) diff -r 92ddfc548ce8 -r 785465f8af3d mod_http_upload/mod_http_upload.lua --- 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