Skip to content

Commit

Permalink
Creating a new async prosody http wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacelroy committed Jul 16, 2018
1 parent cc27e96 commit 944cf42
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions resources/prosody-plugins/util.lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ function wrap_async_run(event,handler)
return true;
end

function async_handler_wrapper(event, handler)
-- Grab a local response so that we can send the http response when
-- the handler is done.
local response = event.response;
local async_func = runner(
function (event)
local result = handler(event)

-- If there is a status code in the result from the
-- wrapped handler then add it to the response.
if tonumber(result.status_code) ~= nil then
response.status_code = result.status_code
end

-- If there are headers in the result from the
-- wrapped handler then add them to the response.
if result.headers ~= nil then
response.headers = result.headers
end

-- Send the response to the waiting http client with
-- or without the body from the wrapped handler.
if result.body ~= nil then
response:send(result.body)
else
response:send();
end
end
)
async_func:run(event)
-- return true to keep the client http connection open.
return true;
end

--- Updates presence stanza, by adding identity node
-- @param stanza the presence stanza
-- @param user the user to which presence we are updating identity
Expand Down Expand Up @@ -158,6 +192,7 @@ return {
is_feature_allowed = is_feature_allowed;
get_room_from_jid = get_room_from_jid;
wrap_async_run = wrap_async_run;
async_handler_wrapper = async_handler_wrapper;
room_jid_match_rewrite = room_jid_match_rewrite;
update_presence_identity = update_presence_identity;
};

0 comments on commit 944cf42

Please sign in to comment.