# Ngx.req.get\_post\_args Issue

**URL:** <https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574>\
**Category:** NGINX\
**Created:** [November 5, 2011, 5:05pm UTC](https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574 "2011-11-05T17:05:31Z")\
**Posts on this page:** 4\
**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:** [November 5, 2011, 5:05pm UTC](https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574/1 "2011-11-05T17:05:31Z")

</div>

-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
START  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
if ngx.var.request\_method == “POST” then  
ngx.req.read\_body()  
local post\_args = ngx.req.get\_post\_args()  
for my\_key, v in pairs( post\_args ) do  
if type(v) == “table” then  
my\_arg = table.concat(v, " ")  
else  
my\_arg = v  
end  
regex\_rules.log\_alert("Alert:- " … my\_key … " ::: " … my\_arg)  
end  
end  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
END  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

The code in ngx\_lua below which should log key/value pairs from a post  
request results in the log output below:

-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
START  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[alert] 17670#0: \*1 Alert:- app\_form[localServerPath] :::  
/home/user/testsite.com/public\_html/share/data/505  
/home/user/testsite.com/public\_html/share/data/505, client:  
89.148.6.249, server: [testsite.com](http://testsite.com), request: “POST // HTTP/1.1”, host:  
“[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”

[alert] 17670#0: \*1 Alert:- app\_form[formName] ::: ItemAddFromServer  
ItemAddFromServer, client: 89.148.6.249, server: [testsite.com](http://testsite.com),  
request: “POST // HTTP/1.1”, host: “[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”  
[debug] 17670#0: \*1 posix\_memalign: 08A6A910:4096 @16

[alert] 17670#0: \*1 Alert:- app\_itemId ::: 470  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_formUrl”

//?app\_view=core.ItemAdmin 470  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_authToken”

8845e98e9296  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_controller”

core.ItemAdd  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_form[formName]”

ItemAddFromServer  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_itemId”

470  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_addPlugin”

ItemAddFromServer  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_form[localServerPath]”

/home/user/testsite.com/public\_html/share/data/505  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name=“app\_form[set][title]”

on  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data;  
name=“app\_form[CreateThumbnailOption][createThumbnail]”

on  
------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data;  
name=“app\_form[action][addFromLocalServer]”

Add Files  
------WebKitFormBoundary3c6CizwarDCoyCst–  
, client: 89.148.6.249, server: [testsite.com](http://testsite.com), request: “POST //  
HTTP/1.1”, host: “[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”

[alert] 17670#0: \*1 Alert:- app\_form[action][findFilesFromLocalServer]  
::: 1 1, client: 89.148.6.249, server: [testsite.com](http://testsite.com), request: “POST //  
HTTP/1.1”, host: “[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”

[alert] 17670#0: \*1 Alert:- ------WebKitFormBoundary3c6CizwarDCoyCst  
Content-Disposition: form-data; name ::: “app\_return”

//?app\_view=core.ItemAdmin, client: 89.148.6.249, server:  
[testsite.com](http://testsite.com), request: “POST // HTTP/1.1”, host: “[testsite.com](http://testsite.com)”,  
referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”

[alert] 17670#0: \*1 Alert:- app\_subView ::: core.ItemAdd core.ItemAdd,  
client: 89.148.6.249, server: [testsite.com](http://testsite.com), request: “POST //  
HTTP/1.1”, host: “[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”

[alert] 17670#0: _1 Alert:- app\_addPlugin ::: ItemAddFromServer  
ItemAddFromServer, client: 89.148.6.249, server: [testsite.com](http://testsite.com),  
request: “POST // HTTP/1.1”, host: “[testsite.com](http://testsite.com)”, referrer:  
“[http://testsite.com/?app\_view=core.ItemAdmin&app\_subView=core.ItemAdd&app\_addPlugin=ItemAddFromServer&app\_form[localServerPath]=/home/user/testsite.com/public\_html/share/data/505&app\_itemId=470&app\_form[action][findFilesFromLocalServer]=1&app\_form[formName]=ItemAddFromServer](http://testsite.com/?app_view=core.ItemAdmin&app_subView=core.ItemAdd&app_addPlugin=ItemAddFromServer&app_form%5BlocalServerPath%5D=/home/user/testsite.com/public_html/share/data/505&app_itemId=470&app_form%5Baction%5D%5BfindFilesFromLocalServer%5D=1&app_form%5BformName%5D=ItemAddFromServer)”  
-_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
END  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

1. The concat command suggests that when “v” is a table, the table  
holds the same value twice. E.G. “[alert] 17670#0: \*1 Alert:-  
app\_form[action][findFilesFromLocalServer] ::: 1 1,” and “[alert]  
17670#0: \*1 Alert:- app\_form[localServerPath] :::  
/home/user/testsite.com/public\_html/share/data/505  
/home/user/testsite.com/public\_html/share/data/505,”

2. The “------WebKitFormBoundary3c6CizwarDCoyCst” lines seem to  
suggest the request body has been somehow attached to one of the  
variables “app\_itemId”. This should just have a value of 140.

I have posted the form that generates this at:  
[http://pastebin.com/6scK6cWP](http://pastebin.com/6scK6cWP). (Pls widen page view to see properly)

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:** [November 6, 2011, 3:39am UTC](https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574/2 "2011-11-06T03:39:36Z")

</div>

On Sun, Nov 6, 2011 at 12:04 AM, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [alert] 17670#0: \*1 Alert:- app\_itemId ::: 470  
> ------WebKitFormBoundary3c6CizwarDCoyCst  
> Content-Disposition: form-data; name=“app\_formUrl”
> 
> //?app\_view=core.ItemAdmin 470  
> ------WebKitFormBoundary3c6CizwarDCoyCst  
> Content-Disposition: form-data; name=“app\_authToken”

Multipart form format is not supported in ngx.req.get\_post\_args. Only  
urlencoded format is supported for now. I’ll make this clear in the  
documentation.

Regards,  
-agentzh

---

<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:** [November 6, 2011, 8:13am UTC](https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574/3 "2011-11-06T08:13:11Z")

</div>

On 6 November 2011 05:38, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Multipart form format is not supported in ngx.req.get\_post\_args. Only  
> urlencoded format is supported for now. I’ll make this clear in the  
> documentation.

Thanks for the clarification..

As I need to have a mix of both types, I have combined three files  
from the cgilua package into one module (cgilua\_module) and using this  
instead.

Handles both multipart and urlencoded formats and outputs a table of  
key/pair values. (Also has “application/xml”, “text/xml”, and  
“text/plain” under the POST request handler. Not yet sure where these  
fit in and just left them in)

My code (work in progress) is now  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
START  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
local ngx\_cgi = require “cgilua\_module”  
if ngx.var.request\_method == “POST” then  
ngx.req.read\_body()  
local post\_args = ngx\_cgi.get\_post\_args()  
for my\_key, v in pairs( post\_args ) do  
if type(v) == “table” then  
my\_arg = table.concat(v, " ")  
else  
my\_arg = v  
end  
regex\_rules.log\_alert("Alert:- " .. my\_key .. " ::: " ..  
my\_arg)  
end  
end  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
END  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Since cgilua has a permissive license, perhaps this, although in lua  
and not C, will be helpful in extending the coverage of  
ngx.req.get\_post\_args to multipart encoded forms.

Cheers!

---

<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:** [November 6, 2011, 11:21am UTC](https://www.ruby-forum.com/t/ngx-req-get-post-args-issue/213574/4 "2011-11-06T11:21:20Z")

</div>

On 6 November 2011 10:12, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> my_arg = table.concat(v, " ")
> else
> my_arg = v
> end
> regex_rules.log_alert("Alert:- " .. my_key .. " ::: " .. my_arg)
> 
> ```
> 
> end  
> end  
> -\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> END  
> -\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

UPDATED

-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
START  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
if ngx.var.request\_method == “POST” then  
– ngx.req.read\_body() – Not needed as cgilua handles this  
local ngx\_cgi = require “cgilua\_module”  
local post\_args = ngx\_cgi.get\_post\_args()  
for my\_key, v in pairs( post\_args ) do  
if type(v) == “table” then  
my\_arg = table.concat(v, " ")  
else  
my\_arg = v  
end  
regex\_rules.log\_alert("Alert:- " .. my\_key .. " ::: " ..  
my\_arg)  
end  
end  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
END  
-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
