aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-01-18 02:03:40 +0100
committerKim Alvefur <zash@zash.se>2019-01-18 02:03:40 +0100
commit19d344e092421bd84cd52de74bcd6b7b1e9a0a13 (patch)
treeca5a098b75459e1d6e4ed6ed183b5f83d8b6c3fb /plugins/mod_http.lua
parent7fefafa8f6cc312b41f69d8149d5a926657bc9fb (diff)
downloadprosody-19d344e092421bd84cd52de74bcd6b7b1e9a0a13.tar.gz
prosody-19d344e092421bd84cd52de74bcd6b7b1e9a0a13.zip
mod_http: Set up to handle OPTIONS
Lower priority to allow http modules to handle it themselves, should they wish to
Diffstat (limited to 'plugins/mod_http.lua')
-rw-r--r--plugins/mod_http.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index 07d1094b..01f20f76 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -119,9 +119,15 @@ function module.add_host(module)
apply_cors_headers(response, opt_methods, opt_headers, opt_max_age, request.headers.origin);
end
+ local function options_handler(event_data)
+ cors_handler(event_data);
+ return "";
+ end
+
for key, handler in pairs(event.item.route or {}) do
local event_name = get_http_event(host, app_path, key);
if event_name then
+ local options_event_name = event_name:gsub("^%S+", "OPTIONS");
if type(handler) ~= "function" then
local data = handler;
handler = function () return data; end
@@ -140,6 +146,7 @@ function module.add_host(module)
app_handlers[event_name] = handler;
module:hook_object_event(server, event_name, handler);
module:hook_object_event(server, event_name, cors_handler, 1);
+ module:hook_object_event(server, options_event_name, options_handler, -1);
else
module:log("warn", "App %s added handler twice for '%s', ignoring", app_name, event_name);
end