Software /
code /
prosody
Changeset
10395:faa4fcc78b14
net.http.server: Handle promises from http handlers
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 01 Nov 2019 22:31:15 +0100 |
parents | 10394:955e54e451dc |
children | 10396:3278f2a31a0a |
files | net/http/server.lua |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/net/http/server.lua Fri Nov 01 22:30:35 2019 +0100 +++ b/net/http/server.lua Fri Nov 01 22:31:15 2019 +0100 @@ -13,6 +13,7 @@ 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 @@ 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