Changeset

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
parents 4513:ade2064160e3
children 4515:2e33eeafe962
files mod_rest/mod_rest.lua
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
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);