# HG changeset patch # User Kim Alvefur # Date 1577853369 -3600 # Node ID dc2b5a412286d6ebad8e9fbfdf8c5e6f2504b5a6 # Parent f88e07630e4e24f11a93955a70cd4b4c1e25b9ff mod_rest: Log sent and received stanzas in style of mod_c2s etc diff -r f88e07630e4e -r dc2b5a412286 mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Tue Dec 31 03:37:46 2019 +0100 +++ b/mod_rest/mod_rest.lua Wed Jan 01 05:36:09 2020 +0100 @@ -1,6 +1,6 @@ -- RESTful API -- --- Copyright (c) 2019 Kim Alvefur +-- Copyright (c) 2019-2020 Kim Alvefur -- -- This file is MIT/X11 licensed. @@ -62,6 +62,7 @@ type = payload.attr.type, ["xml:lang"] = payload.attr["xml:lang"], }; + module:log("debug", "Received[rest]: %s", payload:top_tag()); if payload.name == "iq" then if payload.attr.type ~= "get" and payload.attr.type ~= "set" then return errors.new({ code = 400, text = "'iq' stanza must be of type 'get' or 'set'" }); @@ -69,11 +70,13 @@ return module:send_iq(payload):next( function (result) response.headers.content_type = "application/xmpp+xml"; + module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); return tostring(result.stanza); end, function (error) if error.context.stanza then response.headers.content_type = "application/xmpp+xml"; + module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag()); return tostring(error.context.stanza); else return error; @@ -82,6 +85,7 @@ elseif payload.name == "message" or payload.name == "presence" then local origin = {}; function origin.send(stanza) + module:log("debug", "Sending[rest]: %s", stanza:top_tag()); response:send(tostring(stanza)); return true; end @@ -149,6 +153,7 @@ -- Keep only the top level element and let the rest be GC'd stanza = st.clone(stanza, true); + module:log("debug", "Sending[rest]: %s", stanza:top_tag()); http.request(rest_url, { body = request_body, headers = { @@ -211,6 +216,8 @@ reply:add_direct_child(receipt); end + module:log("debug", "Received[rest]: %s", reply:top_tag()); + origin.send(reply); end);