Skip to content

Instantly share code, notes, and snippets.

@solso
Created April 11, 2013 16:57
Show Gist options
  • Save solso/5365140 to your computer and use it in GitHub Desktop.
Save solso/5365140 to your computer and use it in GitHub Desktop.
extract nested params on query_string
function get_query_args_extended()
args = ngx.req.get_query_args()
for k, v in pairs(args) do
t = {}
for k2 in string.gmatch(k, "%b[]") do
table.insert(t,string.sub(k2,2,string.len(k2)-1))
end
if #t > 0 then
-- it has nested params, needs to be transformed
first = string.sub(k,1,string.find(k,"%[")-1)
if args[first]==nil or type(args[first])~="table" then
args[first] = {}
end
args[first][t[1]] = v
end
end
return args
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment