Software /
code /
prosody-modules
Diff
mod_http_upload/mod_http_upload.lua @ 2692:785465f8af3d
mod_http_upload: Guess mime type from file extension if not provided by client (mime-type is OPTIONAL)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 16 Apr 2017 00:58:02 +0200 |
parent | 2691:92ddfc548ce8 |
child | 2731:d48faff92490 |
line wrap: on
line diff
--- 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