Lua_need_request_body limitations?

So I managed to get my config going smoothly with “GET” requests as
outlined here:
http://mailman.nginx.org/pipermail/nginx/2011-October/029901.html
with this correction
http://mailman.nginx.org/pipermail/nginx/2011-October/029903.html

I then decided to extend to cover “POST” requests.

Here is the calling location:

location @proxy_no_cache {
lua_need_request_body on;
access_by_lua_file ‘/etc/nginx/firewall.lua’;

proxy_pass http://127.0.0.1:8080;

}

firewall.lua contains:


– Check “GET” Args
local args = ngx.req.get_uri_args()
for key, val in pairs(args) do
if type(val) == “table” then
my_arg = table.concat(val, “, “)
else
my_arg = val
end
if my_arg and type( my_arg ) ~= “boolean” then
dofile(”/etc/nginx/regex_rules.lua”)
end
end

– Check “POST” Args
local args = ngx.req.get_post_args()
for key, val in pairs(args) do
if type(val) == “table” then
my_arg = table.concat(val, “, “)
else
my_arg = val
end
if my_arg and type( my_arg ) ~= “boolean” then
dofile(”/etc/nginx/regex_rules.lua”)
end
end
ngx.exit(ngx.OK)

The ‘Check “GET” Args’ bit works fine but the ‘Check “POST” Args’ bit
falls over with …
‘lua handler aborted: runtime error: /etc/nginx/firewall.lua:54: no
request body found; maybe you should turn on lua_need_request_body?,
blah, blah, blah’

Question is that, are there limitations on calling
lua_need_request_body on that my set up does not meet?

Thanks.

On 21 October 2011 18:04, Nginx U. [email protected] wrote:

   lua_need_request_body on;

local args = ngx.req.get_uri_args()

   end

end
ngx.exit(ngx.OK)

My mistake. Needed to make the blocks conditional

– Check “GET” Args
if ngx.var.request_method == “GET” then
local args = ngx.req.get_uri_args()
for key, val in pairs(args) do
if type(val) == “table” then
my_arg = table.concat(val, “, “)
else
my_arg = val
end
if my_arg and type( my_arg ) ~= “boolean” then
dofile(”/etc/nginx/regex_rules.lua”)
end
end
end

– Check “POST” Args
if ngx.var.request_method == “POST” then
local args = ngx.req.get_post_args()
for key, val in pairs(args) do
if type(val) == “table” then
my_arg = table.concat(val, “, “)
else
my_arg = val
end
if my_arg and type( my_arg ) ~= “boolean” then
dofile(”/etc/nginx/regex_rules.lua”)
end
end
end
ngx.exit(ngx.OK)