# HG changeset patch # User Kim Alvefur # Date 1572643875 -3600 # Node ID faa4fcc78b143b86a21a53e7cebd9c9b3d989c2f # Parent 955e54e451dc674fda61a72d6c7d3b9c4e79c10e net.http.server: Handle promises from http handlers diff -r 955e54e451dc -r faa4fcc78b14 net/http/server.lua --- 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