mod_http: Fix pattern and slightly improve efficiency and memory usage of wildcard HTTP handlers
authorMatthew Wild <mwild1@gmail.com>
Thu, 29 Nov 2012 07:15:04 +0500
changeset 5204 0b4f680ea116
parent 5202 ff0d0cd07c43
child 5205 f7ff48494c2b
child 5207 c5edb08fc7cb
mod_http: Fix pattern and slightly improve efficiency and memory usage of wildcard HTTP handlers
plugins/mod_http.lua
--- a/plugins/mod_http.lua	Sun Nov 25 05:12:13 2012 +0100
+++ b/plugins/mod_http.lua	Thu Nov 29 07:15:04 2012 +0500
@@ -88,10 +88,10 @@
 					local data = handler;
 					handler = function () return data; end
 				elseif event_name:sub(-2, -1) == "/*" then
-					local base_path = event_name:match("/(.+)/*$");
+					local base_path_len = #event_name:match("(/.+/)%*$")+1;
 					local _handler = handler;
 					handler = function (event)
-						local path = event.request.path:sub(#base_path+1);
+						local path = event.request.path:sub(base_path_len);
 						return _handler(event, path);
 					end;
 				end