Parcourir la source

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
j8
Jacob MacElroy il y a 7 ans
Parent
révision
fa9a4480e6
1 fichiers modifiés avec 9 ajouts et 7 suppressions
  1. 9
    7
      resources/prosody-plugins/util.lib.lua

+ 9
- 7
resources/prosody-plugins/util.lib.lua Voir le fichier

@@ -62,15 +62,17 @@ end
62 62
 
63 63
 
64 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 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 72
     end)
72 73
     async_func:run(event)
73
-    return result;
74
+    -- return true to keep the client http connection open.
75
+    return true;
74 76
 end
75 77
 
76 78
 --- Updates presence stanza, by adding identity node
@@ -136,4 +138,4 @@ return {
136 138
     wrap_async_run = wrap_async_run;
137 139
     room_jid_match_rewrite = room_jid_match_rewrite;
138 140
     update_presence_identity = update_presence_identity;
139
-};
141
+};

Chargement…
Annuler
Enregistrer