aboutsummaryrefslogtreecommitdiffstats
path: root/net/http/server.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-22 12:24:42 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-22 12:24:42 +0100
commit51a8e815adf0c115d182309e4b6ae993334e986e (patch)
tree6dc8189d78eef9c17ed27f266b104a404f70a35c /net/http/server.lua
parentc6bc3b2fee0af0eef6c033fdc7acca3007c5b910 (diff)
downloadprosody-51a8e815adf0c115d182309e4b6ae993334e986e.tar.gz
prosody-51a8e815adf0c115d182309e4b6ae993334e986e.zip
net.server.http: Ensure that event map cannot grow forever (limit to 10K wildcard-only entries)
Diffstat (limited to 'net/http/server.lua')
-rw-r--r--net/http/server.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index a983b8d5..3c2b55d5 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -27,6 +27,8 @@ local function is_wildcard_match(wildcard_event, event)
return wildcard_event:sub(1, -2) == event:sub(1, #wildcard_event-1);
end
+local recent_wildcard_events, max_cached_wildcard_events = {}, 10000;
+
local event_map = events._event_map;
setmetatable(events._handlers, {
__index = function (handlers, curr_event)
@@ -58,6 +60,12 @@ setmetatable(events._handlers, {
handlers_array = false;
end
rawset(handlers, curr_event, handlers_array);
+ if not event_map[curr_event] then -- Only wildcard handlers match, if any
+ table.insert(recent_wildcard_events, curr_event);
+ if #recent_wildcard_events > max_cached_wildcard_events then
+ rawset(handlers, table.remove(recent_wildcard_events, 1), nil);
+ end
+ end
return handlers_array;
end;
__newindex = function (handlers, curr_event, handlers_array)