diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-08-10 17:49:10 -0400 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-08-10 17:49:10 -0400 |
commit | 0849d44380369efbbc5efc77897eb658cfb8d418 (patch) | |
tree | 776b412d3524a013ca673bbcd3c7335634553845 | |
parent | f0ec18a8b7e8621384970c9803d56c9b1eb92178 (diff) | |
download | prosody-0849d44380369efbbc5efc77897eb658cfb8d418.tar.gz prosody-0849d44380369efbbc5efc77897eb658cfb8d418.zip |
net.http: Add formdecode to decode an urlencoded form
-rw-r--r-- | net/http.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/net/http.lua b/net/http.lua index 6c8e0a68..5b9831ac 100644 --- a/net/http.lua +++ b/net/http.lua @@ -38,6 +38,7 @@ local function _formencodepart(s) end end)); end + function formencode(form) local result = {}; for _, field in ipairs(form) do @@ -46,6 +47,18 @@ function formencode(form) return t_concat(result, "&"); end +function formdecode(s) + if not s:match("=") then return urldecode(s); end + local r = {}; + for k, v in s:gmatch("([^=&]*)=([^&]*)") do + k, v = k:gsub("%+", "%%20"), v:gsub("%+", "%%20"); + k, v = urldecode(k), urldecode(v); + t_insert(r, { name = k, value = v }); + r[k] = v; + end + return r; +end + local function request_reader(request, data, startpos) if not request.parser then local function success_cb(r) |