-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Add FFI functions for ngx.req.get_post_args #87
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -570,3 +570,90 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ | |
[error] | ||
bad argument type | ||
stitch | ||
|
||
|
||
|
||
=== TEST 17: ngx.req.get_post_args | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location = /t { | ||
set $foo hello; | ||
content_by_lua_block { | ||
ngx.req.read_body() | ||
local args | ||
for i = 1, 200 do | ||
args = ngx.req.get_post_args() | ||
end | ||
if type(args) ~= "table" then | ||
ngx.say("bad args type found: ", args) | ||
return | ||
end | ||
local keys = {} | ||
for k, _ in pairs(args) do | ||
keys[#keys + 1] = k | ||
end | ||
table.sort(keys) | ||
for _, k in ipairs(keys) do | ||
local v = args[k] | ||
if type(v) == "table" then | ||
ngx.say(k, ": ", table.concat(v, ", ")) | ||
else | ||
ngx.say(k, ": ", v) | ||
end | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t | ||
a=3%200&foo%20bar=&a=hello&blah | ||
--- response_body | ||
a: 3 0, hello | ||
blah: true | ||
foo bar: | ||
--- error_log eval | ||
qr/\[TRACE \d+ .*? -> \d+\]/ | ||
--- no_error_log | ||
[error] | ||
-- NYI: | ||
--- wait: 0.2 | ||
|
||
|
||
|
||
=== TEST 18: ngx.req.get_post_args (empty) | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location = /t { | ||
set $foo hello; | ||
content_by_lua_block { | ||
ngx.req.read_body() | ||
local args | ||
for i = 1, 200 do | ||
args = ngx.req.get_post_args() | ||
end | ||
if type(args) ~= "table" then | ||
ngx.say("bad args type found: ", args) | ||
return | ||
end | ||
local keys = {} | ||
for k, _ in pairs(args) do | ||
keys[#keys + 1] = k | ||
end | ||
table.sort(keys) | ||
for _, k in ipairs(keys) do | ||
local v = args[k] | ||
if type(v) == "table" then | ||
ngx.say(k, ": ", table.concat(v, ", ")) | ||
else | ||
ngx.say(k, ": ", v) | ||
end | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t? | ||
--- response_body | ||
--- error_log eval | ||
qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ | ||
--- no_error_log | ||
[error] | ||
-- NYI: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases in this library for the FFI-version of ngx_lua's Lua API should focus instead of JIT-ability instead of functionality. Functionality tests are already in the ngx_lua module and ngx_lua's test suite can run with lua-resty-core with the following environment setting, for example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we go against Mike Pall's advice not to cache table lookup in such a hot code path? I am not sure, just to be clear, just raising a concern we previously talked about :)
This happens a bunch in this function, although, I do agree that it makes the code more readable :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think style consistency is important here; this loop is a duplicate of the one for URI args, so this seems the most appropriate choice. I would be interested in looking at some jit dump output of the two approaches and seeing what the functional difference is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm really unsure too, especially since we're dealing with cdata here and not tables...