Welcome! Log In Create A New Profile

Advanced

Re: lua_need_request_body ... limitations?

Nginx User
October 21, 2011 11:34AM
On 21 October 2011 18:04, Nginx User <nginx@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)

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

lua_need_request_body ... limitations?

Nginx User October 21, 2011 11:06AM

Re: lua_need_request_body ... limitations?

Nginx User October 21, 2011 11:34AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 305
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready