diff options
author | Kim Alvefur <zash@zash.se> | 2019-10-10 20:46:27 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-10-10 20:46:27 +0200 |
commit | 8340ca2b183123ba1c1b2d78a155c727f70a9b10 (patch) | |
tree | 405a0b1ea85601fc7cf03f9cd4dbbf49a63d8485 | |
parent | 4394dbf275eb840fe8f4568eca3957560c42c3d0 (diff) | |
download | prosody-8340ca2b183123ba1c1b2d78a155c727f70a9b10.tar.gz prosody-8340ca2b183123ba1c1b2d78a155c727f70a9b10.zip |
mod_http: Unhook CORS related event handlers
Prevents CORS related handlers from being left over on reload.
BC: `mod_http.apps[app_name][event_name]` is now a table instead of the
main handler function.
-rw-r--r-- | plugins/mod_http.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 654ec6c7..8ef06dc2 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -154,7 +154,11 @@ function module.add_host(module) 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; + app_handlers[event_name] = { + main = handler; + cors = cors_handler; + options = options_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); @@ -176,8 +180,11 @@ function module.add_host(module) local function http_app_removed(event) local app_handlers = apps[event.item.name]; apps[event.item.name] = nil; - for event_name, handler in pairs(app_handlers) do - module:unhook_object_event(server, event_name, handler); + for event_name, handlers in pairs(app_handlers) do + module:unhook_object_event(server, event_name, handlers.main); + module:unhook_object_event(server, event_name, handlers.cors); + local options_event_name = event_name:gsub("^%S+", "OPTIONS"); + module:unhook_object_event(server, options_event_name, handlers.options); end end |