浏览代码

Fixing an issue with asnyc http request handlers.

The current poltergeist http api immediately returns
and does not wait for async work in the handler to finish. This
mostly occurs when a public asap key needs to be fetched due
to a cache miss. The fix implements the strategy described at
https://prosody.im/doc/developers/http.html
master
Jacob MacElroy 7 年前
父节点
当前提交
fa9a4480e6
共有 1 个文件被更改,包括 9 次插入7 次删除
  1. 9
    7
      resources/prosody-plugins/util.lib.lua

+ 9
- 7
resources/prosody-plugins/util.lib.lua 查看文件

62
 
62
 
63
 
63
 
64
 function wrap_async_run(event,handler)
64
 function wrap_async_run(event,handler)
65
-    local result;
65
+    -- Grab a local response so that we can send the http response when
66
+    -- the handler is done.
67
+    local response = event.response;
66
     local async_func = runner(function (event)
68
     local async_func = runner(function (event)
67
-        local wait, done = waiter();
68
-        result=handler(event);
69
-        done();
70
-        return result;
69
+          response.status_code = handler(event);
70
+          -- Send the response to the waiting http client.
71
+          response:send();
71
     end)
72
     end)
72
     async_func:run(event)
73
     async_func:run(event)
73
-    return result;
74
+    -- return true to keep the client http connection open.
75
+    return true;
74
 end
76
 end
75
 
77
 
76
 --- Updates presence stanza, by adding identity node
78
 --- Updates presence stanza, by adding identity node
136
     wrap_async_run = wrap_async_run;
138
     wrap_async_run = wrap_async_run;
137
     room_jid_match_rewrite = room_jid_match_rewrite;
139
     room_jid_match_rewrite = room_jid_match_rewrite;
138
     update_presence_identity = update_presence_identity;
140
     update_presence_identity = update_presence_identity;
139
-};
141
+};

正在加载...
取消
保存