Comparison

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
comparison
equal deleted inserted replaced
4513:ade2064160e3 4514:81d0748bff5b
229 229
230 local function handle_request(event, path) 230 local function handle_request(event, path)
231 local request, response = event.request, event.response; 231 local request, response = event.request, event.response;
232 local from; 232 local from;
233 local origin; 233 local origin;
234 local echo = path == "echo";
235 if echo then path = nil; end
234 236
235 if not request.headers.authorization then 237 if not request.headers.authorization then
236 response.headers.www_authenticate = www_authenticate_header; 238 response.headers.www_authenticate = www_authenticate_header;
237 return post_errors.new("noauthz"); 239 return post_errors.new("noauthz");
238 else 240 else
283 ["xml:lang"] = payload.attr["xml:lang"], 285 ["xml:lang"] = payload.attr["xml:lang"],
284 }; 286 };
285 287
286 module:log("debug", "Received[rest]: %s", payload:top_tag()); 288 module:log("debug", "Received[rest]: %s", payload:top_tag());
287 local send_type = decide_type((request.headers.accept or "") ..",".. (request.headers.content_type or ""), supported_outputs) 289 local send_type = decide_type((request.headers.accept or "") ..",".. (request.headers.content_type or ""), supported_outputs)
290
291 if echo then
292 response.headers.content_type = send_type;
293 return encode(send_type, payload);
294 end
295
288 if payload.name == "iq" then 296 if payload.name == "iq" then
289 function origin.send(stanza) 297 function origin.send(stanza)
290 module:send(stanza); 298 module:send(stanza);
291 end 299 end
292 300