Comparison

mod_rest/mod_rest.lua @ 4247:1f93fa24611d

mod_rest: Use promise based HTTP client API Doesn't really simplify anything much.
author Kim Alvefur <zash@zash.se>
date Sun, 15 Nov 2020 15:33:56 +0100
parent 4245:7bf3bf81c9ef
child 4249:64aa1d9d70ac
comparison
equal deleted inserted replaced
4246:53ae1df31950 4247:1f93fa24611d
320 headers = { 320 headers = {
321 ["Content-Type"] = send_type, 321 ["Content-Type"] = send_type,
322 ["Content-Language"] = stanza.attr["xml:lang"], 322 ["Content-Language"] = stanza.attr["xml:lang"],
323 Accept = table.concat(supported_inputs, ", "); 323 Accept = table.concat(supported_inputs, ", ");
324 }, 324 },
325 }, function (body, code, response) 325 }):next(function (response)
326 if code == 0 then 326 module:set_status("info", "Connected");
327 module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body);
328 origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", body));
329 return;
330 else
331 module:set_status("info", "Connected");
332 end
333 local reply; 327 local reply;
334 328
329 local code, body = response.code, response.body;
335 if code == 202 or code == 204 then 330 if code == 202 or code == 204 then
336 if not reply_needed then 331 if not reply_needed then
337 -- Delivered, no reply 332 -- Delivered, no reply
338 return; 333 return;
339 end 334 end
391 end 386 end
392 387
393 module:log("debug", "Received[rest]: %s", reply:top_tag()); 388 module:log("debug", "Received[rest]: %s", reply:top_tag());
394 389
395 origin.send(reply); 390 origin.send(reply);
391 end,
392 function (err)
393 module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, err);
394 origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", err.text));
396 end); 395 end);
397 396
398 return true; 397 return true;
399 end 398 end
400 399