Hi, thank you for your response .. i tried to implement the feature as you suggested - in lua using your module
location /datacenter {
lua_need_request_body on;
client_max_body_size 20k;
client_body_buffer_size 20k;
content_by_lua '
res1, res2 = ngx.location.capture_multi({{"/data1", { method = ngx.HTTP_POST, body = ngx.var.request_body } }, {"/data2", { method = ngx.HTTP_POST, body = ngx.var.request_body} }})
if (res1.status ~= ngx.HTTP_OK and res2.status ~= ngx.HTTP_OK) then
ngx.exit(204)
elseif res1.status ~= ngx.HTTP_OK then
ngx.print(res2.body)
ngx.exit(ngx.HTTP_OK)
elseif res2.status ~= ngx.HTTP_OK then
ngx.print(res1.body)
ngx.exit(ngx.HTTP_OK)
end
ngx.log(ngx.ERR, res1.body) <------------------- i got empty string here - so i cant parse content , but if i call ngx.print(res1.body) the body prints fine to the result
i, j = string.find(res1.body, "data", 0, 1)
k,r = string.find(res1.body, ":", j - 1, 1)
i = string.find(res1.body, ",", k, 1)
data1 = tonumber(string.sub(res1.body, k + 1, i - 1))
i,j = string.find(res2.body, "data",0,1)
k = string.find(res2.body, ":", j, 1)
i = string.find(res2.body, ",", k, 1)
data2 = tonumber(string.sub(res2.body, k + 1, i - 1))
if data1 > data2 then
ngx.print(res1.body)
else
ngx.print(res2.body)
end
ngx.exit(ngx.HTTP_OK)
';
}
the subrequests body are available only after calling ngx.print(subrequest.body).. but it's of course printing the body of subrequest to response of request (which i'm trying to avoid because i didn't make decision which subrequest body to send)
can you tell me what am i doing wrong ?