comparison mod_rest/mod_rest.lua @ 3799:a1f1f703d604

mod_rest: Allow collection of original stanza after sending HTTP request Probably a premature optimization, but there should be no need to keep the full original stanza after this point.
author Kim Alvefur <zash@zash.se>
date Mon, 30 Dec 2019 05:19:23 +0100
parents 9b4fd2553365
children d59fb4dcf100
comparison
equal deleted inserted replaced
3798:9b4fd2553365 3799:a1f1f703d604
125 if stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then 125 if stanza.name == "message" and stanza.attr.id and stanza:get_child("urn:xmpp:receipts", "request") then
126 reply_needed = true; 126 reply_needed = true;
127 receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id }); 127 receipt = st.stanza("received", { xmlns = "urn:xmpp:receipts", id = stanza.id });
128 end 128 end
129 129
130 local request_body = tostring(stanza);
131
132 -- Keep only the top level element and let the rest be GC'd
133 stanza = st.clone(stanza, true);
134
130 http.request(rest_url, { 135 http.request(rest_url, {
131 body = tostring(stanza), 136 body = request_body,
132 headers = { 137 headers = {
133 ["Content-Type"] = "application/xmpp+xml", 138 ["Content-Type"] = "application/xmpp+xml",
134 ["Content-Language"] = stanza.attr["xml:lang"], 139 ["Content-Language"] = stanza.attr["xml:lang"],
135 Accept = "application/xmpp+xml, text/plain", 140 Accept = "application/xmpp+xml, text/plain",
136 }, 141 },