aboutsummaryrefslogtreecommitdiffstats
path: root/net/http/server.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-24 19:07:12 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-24 19:07:12 +0100
commitb23e6a2ef012c2d2568766ef0f41aaadf3cac826 (patch)
treeb4ec8ae969375fa44affd63b323a612bb224afb0 /net/http/server.lua
parent58896e197237213df9061f5e141530387887f814 (diff)
downloadprosody-b23e6a2ef012c2d2568766ef0f41aaadf3cac826.tar.gz
prosody-b23e6a2ef012c2d2568766ef0f41aaadf3cac826.zip
net.http.server: Handle results returned by handlers, and send as a response. Also removes explicit firing of '*', which can now be done via wildcard events.
Diffstat (limited to 'net/http/server.lua')
-rw-r--r--net/http/server.lua32
1 files changed, 20 insertions, 12 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index 50a5c5a1..185ac9a0 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -168,19 +168,27 @@ function handle_request(conn, request, finish_cb)
host = host:match("[^:]*"):lower();
local event = request.method.." "..host..request.path:match("[^?]*");
local payload = { request = request, response = response };
- --[[repeat
- if events.fire_event(event, payload) ~= nil then return; end
- event = (event:sub(-1) == "/") and event:sub(1, -1) or event:gsub("[^/]*$", "");
- if event:sub(-1) == "/" then
- event = event:sub(1, -1);
- else
- event = event:gsub("[^/]*$", "");
+ --log("debug", "Firing event: %s", event);
+ local result = events.fire_event(event, payload);
+ if result ~= nil then
+ if result ~= true then
+ local code, body = 200, "";
+ local result_type = type(result);
+ if result_type == "number" then
+ response.status_code = result;
+ elseif result_type == "string" then
+ body = result;
+ elseif result_type == "table" then
+ body = result.body;
+ result.body = nil;
+ for k, v in pairs(result) do
+ response[k] = v;
+ end
+ end
+ response:send(body);
end
- until not event:find("/", 1, true);]]
- --log("debug", "Event: %s", event);
- if events.fire_event(event, payload) ~= nil then return; end
- -- TODO try adding/stripping / at the end, but this needs to work via an HTTP redirect
- if events.fire_event("*", payload) ~= nil then return; end
+ return;
+ end
end
-- if handler not called, fallback to legacy httpserver handlers