Mercurial > prosody-modules
comparison 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 |
| parents | 92ddfc548ce8 |
| children | d48faff92490 |
comparison
equal
deleted
inserted
replaced
| 2691:92ddfc548ce8 | 2692:785465f8af3d |
|---|---|
| 141 return true; | 141 return true; |
| 142 end | 142 end |
| 143 | 143 |
| 144 if mime_map then | 144 if mime_map then |
| 145 local file_ext = filename:match("%.([^.]+)$"); | 145 local file_ext = filename:match("%.([^.]+)$"); |
| 146 if (not file_ext and mimetype ~= "application/octet-stream") or (file_ext and mime_map[file_ext] ~= mimetype) then | 146 if not mimetype then |
| 147 origin.send(st.error_reply(stanza, "modify", "bad-request", "MIME type does not match file extension")); | 147 mimetype = "application/octet-stream"; |
| 148 return true; | 148 if file_ext then |
| 149 mimetype = mime_map[file_ext] or mimetype; | |
| 150 end | |
| 151 else | |
| 152 if (not file_ext and mimetype ~= "application/octet-stream") or (file_ext and mime_map[file_ext] ~= mimetype) then | |
| 153 origin.send(st.error_reply(stanza, "modify", "bad-request", "MIME type does not match file extension")); | |
| 154 return true; | |
| 155 end | |
| 149 end | 156 end |
| 150 end | 157 end |
| 151 | 158 |
| 152 if allowed_file_types then | 159 if allowed_file_types then |
| 153 if not (allowed_file_types:contains(mimetype) or allowed_file_types:contains(mimetype:gsub("/.*", "/*"))) then | 160 if not (allowed_file_types:contains(mimetype) or allowed_file_types:contains(mimetype:gsub("/.*", "/*"))) then |
