Ngx.req.get_post_args Issue

-************************
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, request: “POST // HTTP/1.1”, host:
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

[alert] 17670#0: *1 Alert:- app_form[formName] ::: ItemAddFromServer
ItemAddFromServer, client: 89.148.6.249, server: testsite.com,
request: “POST // HTTP/1.1”, host: “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
[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, request: “POST //
HTTP/1.1”, host: “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

[alert] 17670#0: *1 Alert:- app_form[action][findFilesFromLocalServer]
::: 1 1, client: 89.148.6.249, server: testsite.com, request: “POST //
HTTP/1.1”, host: “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

[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, request: “POST // HTTP/1.1”, host: “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

[alert] 17670#0: *1 Alert:- app_subView ::: core.ItemAdd core.ItemAdd,
client: 89.148.6.249, server: testsite.com, request: “POST //
HTTP/1.1”, host: “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

[alert] 17670#0: 1 Alert:- app_addPlugin ::: ItemAddFromServer
ItemAddFromServer, client: 89.148.6.249, server: testsite.com,
request: “POST // HTTP/1.1”, host: “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
-
***********************
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. (Pls widen page view to see properly)

Thanks

On Sun, Nov 6, 2011 at 12:04 AM, Nginx U. [email protected] 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

On 6 November 2011 05:38, agentzh [email protected] 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!

On 6 November 2011 10:12, Nginx U. [email protected] 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
-************************

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs