Comparison

mod_component_http/mod_component_http.lua @ 2958:13acce68a89c

mod_component_http: Fix to use module:send() instead of origin.send() (thanks Wiktor)
author Matthew Wild <mwild1@gmail.com>
date Tue, 27 Mar 2018 11:36:25 +0100
parent 2952:e8462d6dbc6d
child 2995:032589c801d7
comparison
equal deleted inserted replaced
2957:0f813e22e3fa 2958:13acce68a89c
30 local error = http_error_map[code] or { "cancel", "service-unavailable" }; 30 local error = http_error_map[code] or { "cancel", "service-unavailable" };
31 return st.error_reply(stanza, unpack(error, 1, 3)); 31 return st.error_reply(stanza, unpack(error, 1, 3));
32 end 32 end
33 33
34 function handle_stanza(event) 34 function handle_stanza(event)
35 local origin, stanza = event.origin, event.stanza; 35 local stanza = event.stanza;
36 local request_body = json.encode({ 36 local request_body = json.encode({
37 to = stanza.attr.to; 37 to = stanza.attr.to;
38 from = stanza.attr.from; 38 from = stanza.attr.from;
39 kind = stanza.name; 39 kind = stanza.name;
40 body = stanza.name == "message" and stanza:get_child_text("body") or nil; 40 body = stanza.name == "message" and stanza:get_child_text("body") or nil;
48 local response_data = json.decode(response_text); 48 local response_data = json.decode(response_text);
49 if response_data.stanza then 49 if response_data.stanza then
50 local reply_stanza = xml.parse(response_data.stanza); 50 local reply_stanza = xml.parse(response_data.stanza);
51 if reply_stanza then 51 if reply_stanza then
52 reply_stanza.attr.from, reply_stanza.attr.to = stanza.attr.to, stanza.attr.from; 52 reply_stanza.attr.from, reply_stanza.attr.to = stanza.attr.to, stanza.attr.from;
53 return origin.send(reply_stanza); 53 module:send(reply_stanza);
54 else 54 else
55 module:log("warn", "Unable to parse reply stanza"); 55 module:log("warn", "Unable to parse reply stanza");
56 end 56 end
57 else 57 else
58 local stanza_kind = response_data.kind or "message"; 58 local stanza_kind = response_data.kind or "message";
64 }); 64 });
65 if stanza_kind == "message" and response_data.body then 65 if stanza_kind == "message" and response_data.body then
66 reply_stanza:tag("body"):text(tostring(response_data.body)):up(); 66 reply_stanza:tag("body"):text(tostring(response_data.body)):up();
67 end 67 end
68 module:log("debug", "Sending %s", tostring(reply_stanza)); 68 module:log("debug", "Sending %s", tostring(reply_stanza));
69 return origin.send(reply_stanza); 69 module:send(reply_stanza);
70 end 70 end
71 elseif code >= 200 and code <= 299 then
71 return; 72 return;
72 elseif code >= 200 and code <= 299 then
73 return true;
74 else 73 else
75 return origin.send(error_reply(stanza, code)); 74 module:send(error_reply(stanza, code));
76 end 75 end
76 return true;
77 end); 77 end);
78 return true; 78 return true;
79 end 79 end
80 80
81 for stanza_kind in stanza_kinds do 81 for stanza_kind in stanza_kinds do