Changeset

12923:419e55abd285 0.12

mod_http: Unhook CORS handlers only if active (fixes #1801)
author Kim Alvefur <zash@zash.se>
date Sun, 05 Mar 2023 15:45:01 +0100
parents 12898:4255db0f8e58
children 12924:ae0fba27fc24 13021:14ca500f8621
files plugins/mod_http.lua
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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