Diff

plugins/mod_http.lua @ 4669:0e0a72679f77

mod_http: Pass portion of path that matched wildcard to wildcard handlers, as a second parameter
author Matthew Wild <mwild1@gmail.com>
date Mon, 23 Apr 2012 21:34:05 +0100
parent 4667:d0cfc49f3f2b
child 4678:9613673f916a
line wrap: on
line diff
--- a/plugins/mod_http.lua	Mon Apr 23 21:29:18 2012 +0100
+++ b/plugins/mod_http.lua	Mon Apr 23 21:34:05 2012 +0100
@@ -46,6 +46,14 @@
 		for key, handler in pairs(event.item.route or {}) do
 			local event_name = get_http_event(host, app_path, key);
 			if event_name then
+				if event_name:sub(-2, -1) == "/*" then
+					local base_path = event_name:match("/(.+)/*$");
+					local _handler = handler;
+					handler = function (event)
+						local path = event.request.path:sub(#base_path+1);
+						return _handler(event, path);
+					end;
+				end
 				if not app_handlers[event_name] then
 					app_handlers[event_name] = handler;
 					server.add_handler(event_name, handler);