Changeset

3796:d1ad10b76b00

mod_rest: Catch one (1) reply to a POST-ed stanza from an internal source This will primarily cover error replies, and only those generated by the same Prosody instance using the `origin.reply()` method.
author Kim Alvefur <zash@zash.se>
date Mon, 30 Dec 2019 05:14:49 +0100
parents 3795:f51308fcba83
children 3797:ed5d7586a61e
files mod_rest/README.markdown mod_rest/mod_rest.lua
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/README.markdown	Mon Dec 30 04:07:25 2019 +0100
+++ b/mod_rest/README.markdown	Mon Dec 30 05:14:49 2019 +0100
@@ -51,6 +51,11 @@
         </iq>'
 ```
 
+Replies to other kinds of stanzas that are generated by the same Prosody
+instance *MAY* be returned in the HTTP response. Replies from other
+entities (connected clients or remote servers) will not be returned, but
+can be forwarded via the callback API described in the next section.
+
 ## Receiving stanzas
 
 TL;DR: Set this webhook callback URL, get XML `POST`-ed there.
--- a/mod_rest/mod_rest.lua	Mon Dec 30 04:07:25 2019 +0100
+++ b/mod_rest/mod_rest.lua	Mon Dec 30 05:14:49 2019 +0100
@@ -63,7 +63,13 @@
 				end
 			end);
 	elseif payload.name == "message" or payload.name == "presence" then
-		if module:send(payload) then
+		local origin = {};
+		function origin.send(stanza)
+			response:send(tostring(stanza));
+			return true;
+		end
+		response.headers.content_type = "application/xmpp+xml";
+		if module:send(payload, origin) then
 			return 202;
 		else
 			return 500;