Comparison

mod_rest/mod_rest.lua @ 4699:a8af632daf48

mod_rest: Support returning multiple replies in an <xmpp> container Allows retrieving MAM results and possibly other things.
author Kim Alvefur <zash@zash.se>
date Wed, 29 Sep 2021 00:26:44 +0200
parent 4532:183c2abdc3c4
child 4727:e6f46d1b3337
comparison
equal deleted inserted replaced
4698:4157773ed4d3 4699:a8af632daf48
291 response.headers.content_type = send_type; 291 response.headers.content_type = send_type;
292 return encode(send_type, payload); 292 return encode(send_type, payload);
293 end 293 end
294 294
295 if payload.name == "iq" then 295 if payload.name == "iq" then
296 local responses = st.stanza("xmpp");
296 function origin.send(stanza) 297 function origin.send(stanza)
297 module:send(stanza); 298 responses:add_direct_child(stanza);
298 end 299 end
299 300
300 if payload.attr.type ~= "get" and payload.attr.type ~= "set" then 301 if payload.attr.type ~= "get" and payload.attr.type ~= "set" then
301 return post_errors.new("iq_type"); 302 return post_errors.new("iq_type");
302 elseif #payload.tags ~= 1 then 303 elseif #payload.tags ~= 1 then
305 306
306 return module:send_iq(payload, origin):next( 307 return module:send_iq(payload, origin):next(
307 function (result) 308 function (result)
308 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); 309 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag());
309 response.headers.content_type = send_type; 310 response.headers.content_type = send_type;
311 if responses[2] then
312 return encode(send_type, responses);
313 end
310 return encode(send_type, result.stanza); 314 return encode(send_type, result.stanza);
311 end, 315 end,
312 function (error) 316 function (error)
313 if not errors.is_err(error) then 317 if not errors.is_err(error) then
314 module:log("error", "Uncaught native error: %s", error); 318 module:log("error", "Uncaught native error: %s", error);