comparison mod_rest/mod_rest.lua @ 3867:839224be5299

mod_rest: Skip attempting parse empty response Avoids logging a useless warning
author Kim Alvefur <zash@zash.se>
date Sun, 26 Jan 2020 04:07:07 +0100
parents c0df50ce96f0
children 513a8a7fab41
comparison
equal deleted inserted replaced
3866:c0df50ce96f0 3867:839224be5299
227 origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", body)); 227 origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", body));
228 return; 228 return;
229 else 229 else
230 module:set_status("info", "Connected"); 230 module:set_status("info", "Connected");
231 end 231 end
232 if (code == 202 or code == 204) and not reply_needed then
233 -- Delivered, no reply
234 return;
235 end
236 local reply; 232 local reply;
237 233
238 local parsed, err = parse(response.headers["content-type"], body); 234 if code == 202 or code == 204 then
239 if not parsed then 235 if not reply_needed then
240 module:log("warn", "Failed parsing data from REST callback: %s, %q", err, body); 236 -- Delivered, no reply
241 elseif parsed.name ~= stanza.name then 237 return;
242 module:log("warn", "REST callback responded with the wrong stanza type, got %s but expected %s", parsed.name, stanza.name); 238 end
243 else 239 else
244 parsed.attr = { 240 local parsed, err = parse(response.headers["content-type"], body);
245 from = stanza.attr.to, 241 if not parsed then
246 to = stanza.attr.from, 242 module:log("warn", "Failed parsing data from REST callback: %s, %q", err, body);
247 id = parsed.attr.id or id.medium(); 243 elseif parsed.name ~= stanza.name then
248 type = parsed.attr.type, 244 module:log("warn", "REST callback responded with the wrong stanza type, got %s but expected %s", parsed.name, stanza.name);
249 ["xml:lang"] = parsed.attr["xml:lang"], 245 else
250 }; 246 parsed.attr = {
251 if parsed.name == "message" and parsed.attr.type == "groupchat" then 247 from = stanza.attr.to,
252 parsed.attr.to = jid.bare(stanza.attr.from); 248 to = stanza.attr.from,
249 id = parsed.attr.id or id.medium();
250 type = parsed.attr.type,
251 ["xml:lang"] = parsed.attr["xml:lang"],
252 };
253 if parsed.name == "message" and parsed.attr.type == "groupchat" then
254 parsed.attr.to = jid.bare(stanza.attr.from);
255 end
256 if not stanza.attr.type and parsed:get_child("error") then
257 parsed.attr.type = "error";
258 end
259 if parsed.attr.type == "error" then
260 parsed.attr.id = stanza.attr.id;
261 elseif parsed.name == "iq" then
262 parsed.attr.id = stanza.attr.id;
263 parsed.attr.type = "result";
264 end
265 reply = parsed;
253 end 266 end
254 if not stanza.attr.type and parsed:get_child("error") then
255 parsed.attr.type = "error";
256 end
257 if parsed.attr.type == "error" then
258 parsed.attr.id = stanza.attr.id;
259 elseif parsed.name == "iq" then
260 parsed.attr.id = stanza.attr.id;
261 parsed.attr.type = "result";
262 end
263 reply = parsed;
264 end 267 end
265 268
266 if not reply then 269 if not reply then
267 local code_hundreds = code - (code % 100); 270 local code_hundreds = code - (code % 100);
268 if code_hundreds == 200 then 271 if code_hundreds == 200 then