Mercurial > prosody-modules
comparison mod_rest/mod_rest.lua @ 3832:0d4146cf9fbc
mod_rest: Enforce single child policy for outgoing it stanzas
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Jan 2020 18:29:10 +0100 |
parents | 802087d3155a |
children | 501c7edc8c37 |
comparison
equal
deleted
inserted
replaced
3831:435f5b4ebd06 | 3832:0d4146cf9fbc |
---|---|
104 module:log("debug", "Received[rest]: %s", payload:top_tag()); | 104 module:log("debug", "Received[rest]: %s", payload:top_tag()); |
105 local send_type = decide_type((request.headers.accept or "") ..",".. request.headers.content_type) | 105 local send_type = decide_type((request.headers.accept or "") ..",".. request.headers.content_type) |
106 if payload.name == "iq" then | 106 if payload.name == "iq" then |
107 if payload.attr.type ~= "get" and payload.attr.type ~= "set" then | 107 if payload.attr.type ~= "get" and payload.attr.type ~= "set" then |
108 return errors.new({ code = 422, text = "'iq' stanza must be of type 'get' or 'set'" }); | 108 return errors.new({ code = 422, text = "'iq' stanza must be of type 'get' or 'set'" }); |
109 elseif #payload.tags ~= 1 then | |
110 return errors.new({ code = 422, text = "'iq' stanza must have exactly one child tag" }); | |
109 end | 111 end |
110 return module:send_iq(payload):next( | 112 return module:send_iq(payload):next( |
111 function (result) | 113 function (result) |
112 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); | 114 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); |
113 response.headers.content_type = send_type; | 115 response.headers.content_type = send_type; |