Merge 0.9->0.10
[prosody.git] / plugins / mod_http_files.lua
index 59fd50aaf630799568e1b50d81cd632003922a2e..2e9f418298ff244614312d2fafd553e2e2371559 100644 (file)
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -14,6 +14,7 @@ local os_date = os.date;
 local open = io.open;
 local stat = lfs.attributes;
 local build_path = require"socket.url".build_path;
+local path_sep = package.config:sub(1,1);
 
 local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path"));
 local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" });
@@ -32,7 +33,7 @@ if not mime_map then
                jpeg = "image/jpeg", jpg = "image/jpeg",
                svg = "image/svg+xml",
        };
-       module:shared("mime").types = mime_map;
+       module:shared("/*/http_files/mime").types = mime_map;
 
        local mime_types, err = open(module:get_option_string("mime_types_file", "/etc/mime.types"),"r");
        if mime_types then
@@ -61,7 +62,7 @@ function serve(opts)
                local request, response = event.request, event.response;
                local orig_path = request.path;
                local full_path = base_path .. (path and "/"..path or "");
-               local attr = stat(full_path);
+               local attr = stat((full_path:gsub('%'..path_sep..'+$','')));
                if not attr then
                        return 404;
                end