lua_need_request_body ... limitations?

Nginx User nginx at nginxuser.net
Fri Oct 21 15:32:32 UTC 2011


On 21 October 2011 18:04, Nginx User <nginx at nginxuser.net> wrote:
> 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)


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)



More information about the nginx mailing list