diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-08-20 16:51:47 -0400 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-08-20 16:51:47 -0400 |
commit | cb11644d8dad6d354d495c95ec67b14fd29ce31e (patch) | |
tree | 2734cd775e696bd4ec8e0239901a92cdac7be5e5 | |
parent | e833a3485d39992a58a015a5a2d853ce6f4a58cd (diff) | |
download | prosody-cb11644d8dad6d354d495c95ec67b14fd29ce31e.tar.gz prosody-cb11644d8dad6d354d495c95ec67b14fd29ce31e.zip |
net.http: Support for k->v maps in http.formencode
-rw-r--r-- | net/http.lua | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/net/http.lua b/net/http.lua index df4d9a02..1fdde22c 100644 --- a/net/http.lua +++ b/net/http.lua @@ -40,8 +40,14 @@ end function formencode(form) local result = {}; - for _, field in ipairs(form) do - t_insert(result, _formencodepart(field.name).."=".._formencodepart(field.value)); + if form[1] then -- Array of ordered { name, value } + for _, field in ipairs(form) do + t_insert(result, _formencodepart(field.name).."=".._formencodepart(field.value)); + end + else -- Unordered map of name -> value + for name, value in pairs(form) do + t_insert(result, _formencodepart(name).."=".._formencodepart(value)); + end end return t_concat(result, "&"); end |