Comparison

plugins/mod_http.lua @ 4696:4700e318add1

mod_http: Use module:hook/unhook_event_object() so that handlers get unregistered if mod_http is unloaded
author Matthew Wild <mwild1@gmail.com>
date Thu, 26 Apr 2012 05:40:04 +0100
parent 4678:9613673f916a
child 4702:5a85e541de1a
comparison
equal deleted inserted replaced
4695:838ad61c6b2c 4696:4700e318add1
55 return _handler(event, path); 55 return _handler(event, path);
56 end; 56 end;
57 end 57 end
58 if not app_handlers[event_name] then 58 if not app_handlers[event_name] then
59 app_handlers[event_name] = handler; 59 app_handlers[event_name] = handler;
60 server.add_handler(event_name, handler); 60 module:hook_object_event(server, event_name, handler);
61 else 61 else
62 module:log("warn", "App %s added handler twice for '%s', ignoring", app_name, event_name); 62 module:log("warn", "App %s added handler twice for '%s', ignoring", app_name, event_name);
63 end 63 end
64 else 64 else
65 module:log("error", "Invalid route in %s: %q", app_name, key); 65 module:log("error", "Invalid route in %s: %q", app_name, key);
69 69
70 local function http_app_removed(event) 70 local function http_app_removed(event)
71 local app_handlers = apps[event.item.name]; 71 local app_handlers = apps[event.item.name];
72 apps[event.item.name] = nil; 72 apps[event.item.name] = nil;
73 for event, handler in pairs(app_handlers) do 73 for event, handler in pairs(app_handlers) do
74 server.remove_handler(event, handler); 74 module:unhook_object_event(server, event, handler);
75 end 75 end
76 end 76 end
77 77
78 module:handle_items("http-provider", http_app_added, http_app_removed); 78 module:handle_items("http-provider", http_app_added, http_app_removed);
79 end 79 end