Software /
code /
prosody
Comparison
plugins/mod_http.lua @ 4724:a8c234332258
mod_http: Allow a route value to be static data rather than a handler function
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 27 Apr 2012 19:02:36 +0100 |
parent | 4721:1c6c4c53f08a |
child | 4736:3514338c59c3 |
comparison
equal
deleted
inserted
replaced
4723:198b11ed196a | 4724:a8c234332258 |
---|---|
49 apps[app_name] = apps[app_name] or {}; | 49 apps[app_name] = apps[app_name] or {}; |
50 local app_handlers = apps[app_name]; | 50 local app_handlers = apps[app_name]; |
51 for key, handler in pairs(event.item.route or {}) do | 51 for key, handler in pairs(event.item.route or {}) do |
52 local event_name = get_http_event(host, app_path, key); | 52 local event_name = get_http_event(host, app_path, key); |
53 if event_name then | 53 if event_name then |
54 if event_name:sub(-2, -1) == "/*" then | 54 if type(handler) ~= "function" then |
55 local data = handler; | |
56 handler = function () return data; end | |
57 elseif event_name:sub(-2, -1) == "/*" then | |
55 local base_path = event_name:match("/(.+)/*$"); | 58 local base_path = event_name:match("/(.+)/*$"); |
56 local _handler = handler; | 59 local _handler = handler; |
57 handler = function (event) | 60 handler = function (event) |
58 local path = event.request.path:sub(#base_path+1); | 61 local path = event.request.path:sub(#base_path+1); |
59 return _handler(event, path); | 62 return _handler(event, path); |