Skip to content
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

feat: support dash in args (#4519) #4676

Merged
merged 19 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ do
val, err = cookie:get(sub_str(key, 8))
if err then
log.warn("failed to fetch cookie value by key: ",
key, " error: ", err)
key, " error: ", err)
nanamikon marked this conversation as resolved.
Show resolved Hide resolved
end
end

elseif core_str.has_prefix(key, "arg_") then
local arg_key = sub_str(key, 5)
local args = request.get_uri_args()[arg_key]
if args then
if type(args) == "table" then
val = args[1]
else
val = args
end
end

Expand Down
66 changes: 66 additions & 0 deletions t/core/ctx2.t
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,69 @@ qr/balancer_ip: 127.0.0.1|balancer_port: 1980/
--- grep_error_log_out
balancer_ip: 127.0.0.1
balancer_port: 1980



=== TEST 5: support dash in the args
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local ngx_ctx = ngx.ctx
local api_ctx = ngx_ctx.api_ctx
if api_ctx == nil then
api_ctx = core.tablepool.fetch("api_ctx", 0, 32)
nanamikon marked this conversation as resolved.
Show resolved Hide resolved
ngx_ctx.api_ctx = api_ctx
end
core.ctx.set_vars_meta(api_ctx)
ngx.say("arg_a-b: ", api_ctx.var["arg_a-b"])
}
}
--- request
GET /t?a-b=aaa
--- response_body
arg_a-b: aaa



=== TEST 6: support dash in the args(Multi args with the same name, only fetch the first one)
nanamikon marked this conversation as resolved.
Show resolved Hide resolved
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local ngx_ctx = ngx.ctx
local api_ctx = ngx_ctx.api_ctx
if api_ctx == nil then
api_ctx = core.tablepool.fetch("api_ctx", 0, 32)
ngx_ctx.api_ctx = api_ctx
end
core.ctx.set_vars_meta(api_ctx)
ngx.say("arg_a-b: ", api_ctx.var["arg_a-b"])
}
}
--- request
GET /t?a-b=aaa&a-b=bbb
--- response_body
arg_a-b: aaa



=== TEST 7: support dash in the args(arg is missing)
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local ngx_ctx = ngx.ctx
local api_ctx = ngx_ctx.api_ctx
if api_ctx == nil then
api_ctx = core.tablepool.fetch("api_ctx", 0, 32)
ngx_ctx.api_ctx = api_ctx
end
core.ctx.set_vars_meta(api_ctx)
ngx.say("arg_a-b: ", api_ctx.var["arg_a-b"])
}
}
--- request
GET /t
--- response_body
arg_a-b: nil