Software /
code /
prosody
Changeset
4338:5d5d6c6d121a
net.http: Add formdecode to decode an urlencoded form
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 10 Aug 2011 17:49:10 -0400 |
parents | 4337:a2ee8ab82dd9 |
children | 4339:63304d323983 |
files | net/http.lua |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/net/http.lua Mon Aug 08 18:23:53 2011 +0200 +++ b/net/http.lua Wed Aug 10 17:49:10 2011 -0400 @@ -38,6 +38,7 @@ end end)); end + function formencode(form) local result = {}; for _, field in ipairs(form) do @@ -46,6 +47,18 @@ 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)