changeset 4944:e67cc71727ca

mod_rest: Fix attempt to index nil in handling of single iq response Fix handling of many responses, break handling of single response :(
author Kim Alvefur <zash@zash.se>
date Tue, 17 May 2022 11:44:44 +0200 (2022-05-17)
parents 83a54f4af94c
children 9d65eb3fcb15
files mod_rest/mod_rest.lua
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Mon May 16 20:31:58 2022 +0200
+++ b/mod_rest/mod_rest.lua	Tue May 17 11:44:44 2022 +0200
@@ -389,9 +389,11 @@
 			function (result)
 				module:log("debug", "Sending[rest]: %s", result.stanza:top_tag());
 				response.headers.content_type = send_type;
-				local tail = responses[#responses];
-				if tail.name ~= "iq" or tail.attr.from ~= result.stanza.attr.from or tail.attr.id ~= result.stanza.attr.id then
-					origin.send(result.stanza);
+				if responses[1] then
+					local tail = responses[#responses];
+					if tail.name ~= "iq" or tail.attr.from ~= result.stanza.attr.from or tail.attr.id ~= result.stanza.attr.id then
+						origin.send(result.stanza);
+					end
 				end
 				if responses[2] then
 					return encode(send_type, responses);