Software /
code /
prosody
Comparison
net/http/server.lua @ 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 |
parent | 4715:4d6ebe54671e |
child | 4727:5ebf4096a2e1 |
comparison
equal
deleted
inserted
replaced
4725:d085db6285db | 4726:917a5ffb73f1 |
---|---|
44 matching_handlers_set[handler] = { (select(2, event:gsub("/", "%1"))), is_wildcard_event(event) and 0 or 1, priority }; | 44 matching_handlers_set[handler] = { (select(2, event:gsub("/", "%1"))), is_wildcard_event(event) and 0 or 1, priority }; |
45 table.insert(handlers_array, handler); | 45 table.insert(handlers_array, handler); |
46 end | 46 end |
47 end | 47 end |
48 end | 48 end |
49 if #handlers_array == 0 then return; end | 49 if #handlers_array > 0 then |
50 table.sort(handlers_array, function(b, a) | 50 table.sort(handlers_array, function(b, a) |
51 local a_score, b_score = matching_handlers_set[a], matching_handlers_set[b]; | 51 local a_score, b_score = matching_handlers_set[a], matching_handlers_set[b]; |
52 for i = 1, #a_score do | 52 for i = 1, #a_score do |
53 if a_score[i] ~= b_score[i] then -- If equal, compare next score value | 53 if a_score[i] ~= b_score[i] then -- If equal, compare next score value |
54 return a_score[i] < b_score[i]; | 54 return a_score[i] < b_score[i]; |
55 end | 55 end |
56 end | 56 end |
57 return false; | 57 return false; |
58 end); | 58 end); |
59 handlers[curr_event] = handlers_array; | 59 else |
60 handlers_array = false; | |
61 end | |
62 rawset(handlers, curr_event, handlers_array); | |
60 return handlers_array; | 63 return handlers_array; |
61 end; | 64 end; |
62 __newindex = function (handlers, curr_event, handlers_array) | 65 __newindex = function (handlers, curr_event, handlers_array) |
63 if handlers_array == nil | 66 if handlers_array == nil |
64 and is_wildcard_event(curr_event) then | 67 and is_wildcard_event(curr_event) then |
67 if is_wildcard_match(curr_event, event) then | 70 if is_wildcard_match(curr_event, event) then |
68 handlers[event] = nil; | 71 handlers[event] = nil; |
69 end | 72 end |
70 end | 73 end |
71 end | 74 end |
75 rawset(handlers, curr_event, handlers_array); | |
72 end; | 76 end; |
73 }); | 77 }); |
74 | 78 |
75 local handle_request; | 79 local handle_request; |
76 local _1, _2, _3; | 80 local _1, _2, _3; |