mod_http: Unhook CORS handlers only if active (fixes #1801) 0.12
authorKim Alvefur <zash@zash.se>
Sun, 05 Mar 2023 15:45:01 +0100
branch0.12
changeset 12927 419e55abd285
parent 12902 4255db0f8e58
child 12928 ae0fba27fc24
child 13025 14ca500f8621
mod_http: Unhook CORS handlers only if active (fixes #1801)
plugins/mod_http.lua
--- a/plugins/mod_http.lua	Wed Feb 22 22:27:42 2023 +0100
+++ b/plugins/mod_http.lua	Sun Mar 05 15:45:01 2023 +0100
@@ -261,7 +261,9 @@
 		apps[event.item.name] = nil;
 		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);
+			if handlers.cors then
+				module:unhook_object_event(server, event_name, handlers.cors);
+			end
 
 			if event_name:sub(-2, -1) == "/*" then
 				module:unhook_object_event(server, event_name:sub(1, -3), redir_handler, -1);
@@ -269,8 +271,10 @@
 				module:unhook_object_event(server, event_name:sub(1, -2), redir_handler, -1);
 			end
 
-			local options_event_name = event_name:gsub("^%S+", "OPTIONS");
-			module:unhook_object_event(server, options_event_name, handlers.options);
+			if handlers.options then
+				local options_event_name = event_name:gsub("^%S+", "OPTIONS");
+				module:unhook_object_event(server, options_event_name, handlers.options);
+			end
 		end
 	end