Software /
code /
prosody
Changeset
4726:917a5ffb73f1
net.http.server: Correctly cache results of handler indexing, and also cache failures
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 27 Apr 2012 20:00:06 +0100 |
parents | 4725:d085db6285db |
children | 4727:5ebf4096a2e1 |
files | net/http/server.lua |
diffstat | 1 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/net/http/server.lua Fri Apr 27 19:05:03 2012 +0100 +++ b/net/http/server.lua Fri Apr 27 20:00:06 2012 +0100 @@ -46,17 +46,20 @@ end end end - if #handlers_array == 0 then return; end - table.sort(handlers_array, function(b, a) - local a_score, b_score = matching_handlers_set[a], matching_handlers_set[b]; - for i = 1, #a_score do - if a_score[i] ~= b_score[i] then -- If equal, compare next score value - return a_score[i] < b_score[i]; + if #handlers_array > 0 then + table.sort(handlers_array, function(b, a) + local a_score, b_score = matching_handlers_set[a], matching_handlers_set[b]; + for i = 1, #a_score do + if a_score[i] ~= b_score[i] then -- If equal, compare next score value + return a_score[i] < b_score[i]; + end end - end - return false; - end); - handlers[curr_event] = handlers_array; + return false; + end); + else + handlers_array = false; + end + rawset(handlers, curr_event, handlers_array); return handlers_array; end; __newindex = function (handlers, curr_event, handlers_array) @@ -69,6 +72,7 @@ end end end + rawset(handlers, curr_event, handlers_array); end; });