X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_http.lua;h=8bda1cac2ea5703536c6ad6b3d6acf1f4d8c7828;hb=45d601d5ebffdd8f41319bddcbeffb901ca5e967;hp=49529ea28b1109c264acc8cdc1ad56d487e3ea17;hpb=ad00f8769f2110e42bb7a7ce83b952abddc0aa19;p=prosody.git diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 49529ea2..8bda1cac 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -45,6 +45,11 @@ local function get_base_path(host_module, app_name, default_app_path) :gsub("%$(%w+)", { host = host_module.host }); end +local function redir_handler(event) + event.response.headers.location = event.request.path.."/"; + return 301; +end + local ports_by_scheme = { http = 80, https = 443, }; -- Helper to deduce a module's external URL @@ -99,6 +104,9 @@ function module.add_host(module) local path = event.request.path:sub(base_path_len); return _handler(event, path); end; + module:hook_object_event(server, event_name:sub(1, -3), redir_handler, -1); + elseif event_name:sub(-1, -1) == "/" then + module:hook_object_event(server, event_name:sub(1, -2), redir_handler, -1); end if not app_handlers[event_name] then app_handlers[event_name] = handler;