location = /madrs{
content_by_lua '
function split(pString, pPattern)
local Table = {n = 0}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
local args = ngx.req.get_uri_args()
local app = ""
local platform = ""
local category_values = { n = 0 }
local location_values = { n = 0 }
local individual_requests = { n = 0 }
for key, val in pairs(args) do
if key == "app" then
app = val
elseif key == "platform" then
platform = val
elseif key == "category" then
category_values = split(val, ",")
elseif key == "location" then
location_values = split(val, ",")
else
error("Invalid URI argument!")
return 0
end
end
if #category_values > 0 and #location_values > 0 then
for i, cat_value in ipairs(category_values) do
for j, loc_value in ipairs(location_values) do
table.insert(individual_requests, {"/madr?app="..app.."&platform="..platform.."&category="..cat_value.."&location="..loc_value})
end
end
else
return 0
end
if #individual_requests > 0 then
local resps = { ngx.location.capture_multi(individual_requests) }