When sending a request_pipeline() using lua-resty-http (https://github.com/pintsized/lua-resty-http.git), I can view all of the responses if I use the following code:
====================================================
local responses = httpc:request_pipeline(RequestTable)
local C = 1
for i,r in ipairs(responses) do
if r.status then
ngx.say(PluginTable[C], "\t", r.status, "\t", #r:read_body())
end
C = C + 1
end
====================================================
However, if I only want to print certain responses, e.g. those with 403 responses I only get a small subset of the responses. Below is an example of the code I'm using:
====================================================
local responses = httpc:request_pipeline(RequestTable)
local C = 1
for i,r in ipairs(responses) do
if r.status == 403 then
ngx.say(PluginTable[C], "\t", r.status, "\t", #r:read_body())
end
C = C + 1
end
====================================================
The above code returns only the first 403 response and not any subsequent 403 response. I understand that no responses are read until you use the response fields, so I also tried dumping all of the responses in a table and then implementing the 403 check logic outside of the loop that initially accesses the responses, but that did not print all of the 403 responses either:
==================================================
local responses = httpc:request_pipeline(RequestTable)
local C = 1
local ResultsTable = {}
for i,r in ipairs(responses) do
if r.status then
ResultsTable[PluginTable[C]] = r.status
end
C = C + 1
end
for q,w in ipairs(ResultsTable) do
if w == 403 then ngx.say(q,w) end
end
======================================================
How can I access all of the request_pipeline() responses but only print a select few based on response status?
thanks!
- G