# HG changeset patch # User Matthew Wild # Date 1313873507 14400 # Node ID 9e2a841739b5468b2f4d57d8d364dde514e4bd98 # Parent 502876d9436372184fb526361f35e330a160ba59 net.http: Support for k->v maps in http.formencode diff -r 502876d94363 -r 9e2a841739b5 net/http.lua --- 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