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
commit5cac177270b40336e9820619e9c6ab3973ad95b4 (patch)
treedaab88194e5b4dc34e876e088d704eceeed747e1 /net/http/server.lua
parentfdfe1e0b2bf8cea4e2e512fa8e25bface008a59b (diff)
downloadprosody-5cac177270b40336e9820619e9c6ab3973ad95b4.tar.gz
prosody-5cac177270b40336e9820619e9c6ab3973ad95b4.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