# HG changeset patch # User Matthew Wild # Date 1313012950 14400 # Node ID 5d5d6c6d121af869359175df050b7aa656abff16 # Parent a2ee8ab82dd9be9f2e7d6778d4e08e5c3e247a0b net.http: Add formdecode to decode an urlencoded form diff -r a2ee8ab82dd9 -r 5d5d6c6d121a net/http.lua --- 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)