I am making a call limiter based on api key and I am keeping counter of calls in redis where key is my api-key and value is a counter. After threshold or allowed call for that key is reached I throw a message stating your quota reached or something.It works fine and response is also quick, but the problem is I cannot access response status of api-server so even if the response is 500 , the call counter gets increased.
Now, what I need to do is, increase counter only if I get status code 2.x.x , but I can only capture response ngx.status
in body_filter_by_lua_file
but in this directive I cannot make connection to redis or postgres. It throws failed to run body_filter_by_lua*: attempt to yield across C-call boundary
error , I can, however connect to redis in content_by_lua_file
but cannot access response status. Hope I made it clear.
PS: I am using latest openresty and lua-resty-redis