aboutsummaryrefslogtreecommitdiffstats
path: root/net/http/server.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-11-01 22:31:15 +0100
committerKim Alvefur <zash@zash.se>2019-11-01 22:31:15 +0100
commit9ea8b29e99e2f8a037dd04384cac0959f47c9c05 (patch)
treedaab88194e5b4dc34e876e088d704eceeed747e1 /net/http/server.lua
parentc53b66920be43a25f5b5a4c65144bf011407dbf9 (diff)
downloadprosody-9ea8b29e99e2f8a037dd04384cac0959f47c9c05.tar.gz
prosody-9ea8b29e99e2f8a037dd04384cac0959f47c9c05.zip
net.http.server: Handle promises from http handlers
Diffstat (limited to 'net/http/server.lua')
-rw-r--r--net/http/server.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index 0d49dbce..dc64728f 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -13,6 +13,7 @@ local traceback = debug.traceback;
local tostring = tostring;
local cache = require "util.cache";
local codes = require "net.http.codes";
+local promise = require "util.promise";
local errors = require "util.error";
local blocksize = 2^16;
@@ -191,6 +192,13 @@ local function handle_result(request, response, result)
body = result;
elseif errors.is_err(result) then
body = events.fire_event("http-error", { request = request, response = response, code = result.code, error = result });
+ elseif promise.is_promise(result) then
+ result:next(function (ret)
+ handle_result(request, response, ret);
+ end, function (err)
+ handle_result(request, response, err);
+ end);
+ return true;
elseif result_type == "table" then
for k, v in pairs(result) do
if k ~= "headers" then