# Lua\_need\_request\_body limitations?

**URL:** <https://www.ruby-forum.com/t/lua-need-request-body-limitations/213046>\
**Category:** NGINX\
**Created:** [October 21, 2011, 5:05pm UTC](https://www.ruby-forum.com/t/lua-need-request-body-limitations/213046 "2011-10-21T17:05:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 21, 2011, 5:05pm UTC](https://www.ruby-forum.com/t/lua-need-request-body-limitations/213046/1 "2011-10-21T17:05:00Z")

</div>

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](http://mailman.nginx.org/pipermail/nginx/2011-October/029901.html)  
with this correction  
[http://mailman.nginx.org/pipermail/nginx/2011-October/029903.html](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](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.

---

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [October 21, 2011, 5:32pm UTC](https://www.ruby-forum.com/t/lua-need-request-body-limitations/213046/2 "2011-10-21T17:32:54Z")

</div>

On 21 October 2011 18:04, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)
