Software /
code /
prosody
Changeset
10315:d4c538a7d655
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 10 Oct 2019 20:46:27 +0200 |
parents | 10314:bbc879eab1bf |
children | 10316:74b49c8b1b79 |
files | plugins/mod_http.lua |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_http.lua Thu Oct 10 16:58:02 2019 +0200 +++ b/plugins/mod_http.lua Thu Oct 10 20:46:27 2019 +0200 @@ -154,7 +154,11 @@ 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 @@ 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