aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2012-04-21 18:23:44 +0500
committerWaqas Hussain <waqas20@gmail.com>2012-04-21 18:23:44 +0500
commit668d1d442a158223979c1510841298dfd4535525 (patch)
tree05aefbad9622090d92b497dc1ad00189168b1653 /plugins
parent10a43c8ff2c3b1e7b9092a88886dd24105527cda (diff)
downloadprosody-668d1d442a158223979c1510841298dfd4535525.tar.gz
prosody-668d1d442a158223979c1510841298dfd4535525.zip
mod_http: Include handlers of non-global modules.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_http.lua40
1 files changed, 28 insertions, 12 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index 4713cf13..24ef8ab3 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -14,28 +14,44 @@ module:set_global();
sessions[conn] = session;
end]]
-local handlers;
+local NULL = {};
+local handlers = {};
-function build_handlers()
- handlers = {};
- for _, item in ipairs(module:get_host_items("http-handler")) do
- local previous = handlers[item.path];
- if not previous and item.path then
- handlers[item.path] = item;
+function build_handlers(host)
+ if not hosts[host] then return; end
+ local h = {};
+ handlers[host] = h;
+
+ for mod_name, module in pairs(modulemanager.get_modules(host)) do
+ module = module.module;
+ if module.items then
+ for _, item in ipairs(module.items["http-handler"] or NULL) do
+ local previous = handlers[item.path];
+ if not previous and item.path then
+ h[item.path] = item;
+ end
+ end
end
end
+
+ return h;
+end
+function clear_handlers(event)
+ handlers[event.source.host] = nil;
end
-function clear_handlers()
- handlers = nil;
+function get_handler(host, path)
+ local h = handlers[host] or build_handlers(host);
+ if h then
+ local item = h[path];
+ return item and item.handler;
+ end
end
module:handle_items("http-handler", clear_handlers, clear_handlers, false);
function http_handler(event)
local request, response = event.request, event.response;
- if not handlers then build_handlers(); end
- local item = handlers[request.path:match("[^?]*")];
- local handler = item and item.handler;
+ local handler = get_handler(request.headers.host:match("[^:]*"):lower(), request.path:match("[^?]*"));
if handler then
handler(request, response);
return true;