changeset 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 04ae5b45e6c7
files mod_http_upload/mod_http_upload.lua
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
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