Software /
code /
prosody
Diff
net/http.lua @ 4355:9e2a841739b5
net.http: Support for k->v maps in http.formencode
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 20 Aug 2011 16:51:47 -0400 |
parent | 4352:912a49b1c4e3 |
child | 4356:10a4f3b081a7 |
line wrap: on
line diff
--- a/net/http.lua Sat Aug 20 16:51:17 2011 -0400 +++ b/net/http.lua Sat Aug 20 16:51:47 2011 -0400 @@ -40,8 +40,14 @@ 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