Diff

mod_rest/mod_rest.lua @ 4514:81d0748bff5b

mod_rest: Add an 'echo' endpoint for debugging It returns the XML stanza built from e.g. the JSON format.
author Kim Alvefur <zash@zash.se>
date Sun, 21 Mar 2021 00:31:53 +0100
parent 4506:508cb880b163
child 4526:23b681214be3
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Wed Mar 17 15:52:12 2021 +0100
+++ b/mod_rest/mod_rest.lua	Sun Mar 21 00:31:53 2021 +0100
@@ -231,6 +231,8 @@
 	local request, response = event.request, event.response;
 	local from;
 	local origin;
+	local echo = path == "echo";
+	if echo then path = nil; end
 
 	if not request.headers.authorization then
 		response.headers.www_authenticate = www_authenticate_header;
@@ -285,6 +287,12 @@
 
 	module:log("debug", "Received[rest]: %s", payload:top_tag());
 	local send_type = decide_type((request.headers.accept or "") ..",".. (request.headers.content_type or ""), supported_outputs)
+
+	if echo then
+		response.headers.content_type = send_type;
+		return encode(send_type, payload);
+	end
+
 	if payload.name == "iq" then
 		function origin.send(stanza)
 			module:send(stanza);