net.http: Add formdecode to decode an urlencoded form

remotes/origin/0.11
Matthew Wild 15 years ago
parent f0ec18a8b7
commit 0849d44380
  1. 13
      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)

Loading…
Cancel
Save