aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-11-04 17:48:17 +0100
committerKim Alvefur <zash@zash.se>2014-11-04 17:48:17 +0100
commit597c04000ed4ddf817b60c704eef03fc4129e9b0 (patch)
treed7a656cc9ea1cf8d1dc2df2e42265187bb74d84e /plugins/mod_http.lua
parent4c8f1bc90a5a869031e37a068342ba51c487f631 (diff)
downloadprosody-597c04000ed4ddf817b60c704eef03fc4129e9b0.tar.gz
prosody-597c04000ed4ddf817b60c704eef03fc4129e9b0.zip
mod_http: For URLs that end with / or wildcard handlers, add a low-priority redirect from without to with slash
Diffstat (limited to 'plugins/mod_http.lua')
-rw-r--r--plugins/mod_http.lua8
1 files changed, 8 insertions, 0 deletions
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;