# HG changeset patch # User Kim Alvefur # Date 1577891950 -3600 # Node ID f027b8b1e794a97f1ce1ff36f92ce184d2c4c2b9 # Parent eb25110696cd3507ffb7a879c75233385b5e9bc8 mod_rest: Factor out serialization of outgoing stanzas More preparation for content negotiation diff -r eb25110696cd -r f027b8b1e794 mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Wed Jan 01 16:01:25 2020 +0100 +++ b/mod_rest/mod_rest.lua Wed Jan 01 16:19:10 2020 +0100 @@ -36,6 +36,10 @@ return "application/xmpp+xml"; end +local function encode(type, s) + return tostring(s); +end + local function handle_post(event) local request, response = event.request, event.response; if not request.headers.authorization then @@ -85,13 +89,13 @@ function (result) module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); response.headers.content_type = send_type; - return tostring(result.stanza); + return encode(send_type, result.stanza); end, function (error) if error.context.stanza then response.headers.content_type = send_type; module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag()); - return tostring(error.context.stanza); + return encode(send_type, error.context.stanza); else return error; end @@ -101,7 +105,7 @@ function origin.send(stanza) module:log("debug", "Sending[rest]: %s", stanza:top_tag()); response.headers.content_type = send_type; - response:send(tostring(stanza)); + response:send(encode(send_type, stanza)); return true; end if module:send(payload, origin) then @@ -161,7 +165,7 @@ receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id }); end - local request_body = tostring(stanza); + local request_body = encode(send_type, stanza); -- Keep only the top level element and let the rest be GC'd stanza = st.clone(stanza, true);