Software /
code /
prosody
Comparison
net/http/server.lua @ 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 |
parent | 10394:955e54e451dc |
child | 10396:3278f2a31a0a |
comparison
equal
deleted
inserted
replaced
10394:955e54e451dc | 10395:faa4fcc78b14 |
---|---|
11 local xpcall = require "util.xpcall".xpcall; | 11 local xpcall = require "util.xpcall".xpcall; |
12 local traceback = debug.traceback; | 12 local traceback = debug.traceback; |
13 local tostring = tostring; | 13 local tostring = tostring; |
14 local cache = require "util.cache"; | 14 local cache = require "util.cache"; |
15 local codes = require "net.http.codes"; | 15 local codes = require "net.http.codes"; |
16 local promise = require "util.promise"; | |
16 local errors = require "util.error"; | 17 local errors = require "util.error"; |
17 local blocksize = 2^16; | 18 local blocksize = 2^16; |
18 | 19 |
19 local _M = {}; | 20 local _M = {}; |
20 | 21 |
189 end | 190 end |
190 elseif result_type == "string" then | 191 elseif result_type == "string" then |
191 body = result; | 192 body = result; |
192 elseif errors.is_err(result) then | 193 elseif errors.is_err(result) then |
193 body = events.fire_event("http-error", { request = request, response = response, code = result.code, error = result }); | 194 body = events.fire_event("http-error", { request = request, response = response, code = result.code, error = result }); |
195 elseif promise.is_promise(result) then | |
196 result:next(function (ret) | |
197 handle_result(request, response, ret); | |
198 end, function (err) | |
199 handle_result(request, response, err); | |
200 end); | |
201 return true; | |
194 elseif result_type == "table" then | 202 elseif result_type == "table" then |
195 for k, v in pairs(result) do | 203 for k, v in pairs(result) do |
196 if k ~= "headers" then | 204 if k ~= "headers" then |
197 response[k] = v; | 205 response[k] = v; |
198 else | 206 else |