Comparison

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
comparison
equal deleted inserted replaced
4668:cce0c739b0d7 4669:0e0a72679f77
44 apps[app_name] = apps[app_name] or {}; 44 apps[app_name] = apps[app_name] or {};
45 local app_handlers = apps[app_name]; 45 local app_handlers = apps[app_name];
46 for key, handler in pairs(event.item.route or {}) do 46 for key, handler in pairs(event.item.route or {}) do
47 local event_name = get_http_event(host, app_path, key); 47 local event_name = get_http_event(host, app_path, key);
48 if event_name then 48 if event_name then
49 if event_name:sub(-2, -1) == "/*" then
50 local base_path = event_name:match("/(.+)/*$");
51 local _handler = handler;
52 handler = function (event)
53 local path = event.request.path:sub(#base_path+1);
54 return _handler(event, path);
55 end;
56 end
49 if not app_handlers[event_name] then 57 if not app_handlers[event_name] then
50 app_handlers[event_name] = handler; 58 app_handlers[event_name] = handler;
51 server.add_handler(event_name, handler); 59 server.add_handler(event_name, handler);
52 else 60 else
53 module:log("warn", "App %s added handler twice for '%s', ignoring", app_name, event_name); 61 module:log("warn", "App %s added handler twice for '%s', ignoring", app_name, event_name);