Mercurial > prosody-modules
changeset 3803:dc2b5a412286
mod_rest: Log sent and received stanzas in style of mod_c2s etc
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Jan 2020 05:36:09 +0100 |
parents | f88e07630e4e |
children | d74509cd35fb |
files | mod_rest/mod_rest.lua |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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);