Software /
code /
prosody-modules
Diff
mod_rest/mod_rest.lua @ 3911:064c32a5be7c
mod_rest: Support urlencoded form data (does a subset of JSON mapping)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 26 Feb 2020 20:14:14 +0100 |
parent | 3910:49efd1323a1b |
child | 3915:80dffbbd056b |
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua Wed Feb 26 18:36:40 2020 +0000 +++ b/mod_rest/mod_rest.lua Wed Feb 26 20:14:14 2020 +0100 @@ -68,13 +68,22 @@ return parsed, err; end return jsonmap.json2st(parsed); + elseif mimetype == "application/x-www-form-urlencoded"then + local parsed = http.formdecode(data); + if type(parsed) == "string" then + return parse("text/plain", parsed); + end + for i = #parsed, 1, -1 do + parsed[i] = nil; + end + return jsonmap.json2st(parsed); elseif mimetype == "text/plain" then return st.message({ type = "chat" }, data); end return nil, "unknown-payload-type"; end -local supported_types = { "application/xmpp+xml", "application/json" }; +local supported_types = { "application/xmpp+xml", "application/json", "application/x-www-form-urlencoded" }; local function decide_type(accept) -- assumes the accept header is sorted