# HG changeset patch # User Kim Alvefur # Date 1582744454 -3600 # Node ID 064c32a5be7c4a9cec42be59de7eb1351369652a # Parent 49efd1323a1bf12e97d3569e121f6e301ad5252b mod_rest: Support urlencoded form data (does a subset of JSON mapping) diff -r 49efd1323a1b -r 064c32a5be7c mod_rest/mod_rest.lua --- 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