Comparison

plugins/mod_http.lua @ 5204:0b4f680ea116

mod_http: Fix pattern and slightly improve efficiency and memory usage of wildcard HTTP handlers
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Nov 2012 07:15:04 +0500
parent 5190:76c73bd3d483
child 5230:6f5640375358
comparison
equal deleted inserted replaced
5202:ff0d0cd07c43 5204:0b4f680ea116
86 if event_name then 86 if event_name then
87 if type(handler) ~= "function" then 87 if type(handler) ~= "function" then
88 local data = handler; 88 local data = handler;
89 handler = function () return data; end 89 handler = function () return data; end
90 elseif event_name:sub(-2, -1) == "/*" then 90 elseif event_name:sub(-2, -1) == "/*" then
91 local base_path = event_name:match("/(.+)/*$"); 91 local base_path_len = #event_name:match("(/.+/)%*$")+1;
92 local _handler = handler; 92 local _handler = handler;
93 handler = function (event) 93 handler = function (event)
94 local path = event.request.path:sub(#base_path+1); 94 local path = event.request.path:sub(base_path_len);
95 return _handler(event, path); 95 return _handler(event, path);
96 end; 96 end;
97 end 97 end
98 if not app_handlers[event_name] then 98 if not app_handlers[event_name] then
99 app_handlers[event_name] = handler; 99 app_handlers[event_name] = handler;