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 | fad05ab1c7d6e083c379ce010e931279c64d023c (patch) | |
tree | 776b412d3524a013ca673bbcd3c7335634553845 /net/http.lua | |
parent | d29b8f340a4c795dd40a856f208d0d22017b328b (diff) | |
download | prosody-fad05ab1c7d6e083c379ce010e931279c64d023c.tar.gz prosody-fad05ab1c7d6e083c379ce010e931279c64d023c.zip |
net.http: Add formdecode to decode an urlencoded form
Diffstat (limited to 'net/http.lua')
-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) |