Skip to content

Commit

Permalink
configuration: take into account POST URI params when matching mappin…
Browse files Browse the repository at this point in the history
…g rules

Suppose we have this mapping rule:
POST /test?key={value}

Before this change, `curl -XPOST "http://localhost:8080/test?key=hello"
-d "another=parameter"` did not match, but `curl -XPOST
"http://localhost:8080/test" -d "key=hello&another=parameter"` did.

That's because in POST requests, body params were taken into account,
but URI params were not. This commit changes that inconsistent
behavior, now both body & URI params are checked.
  • Loading branch information
davidor committed Sep 29, 2017
1 parent 6cedfd4 commit 4bdd0b3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions apicast/src/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,23 @@ local function check_rule(req, rule, usage_t, matched_rules, params)
end

local function get_auth_params(method)
local params
local params = ngx.req.get_uri_args()

if method == "GET" then
params = ngx.req.get_uri_args()
return params
else
ngx.req.read_body()
params = ngx.req.get_post_args()
end
local body_params = ngx.req.get_post_args()

-- Adds to body_params URI params that are not included in the body. Doing
-- the reverse would be more expensive, because in general, we expect the
-- size of body_params to be larger than the size of params.
for k, v in pairs(params) do
if not body_params[k] then body_params[k] = v end
end

return params
return body_params
end
end

local regex_variable = '\\{[-\\w_]+\\}'
Expand Down

0 comments on commit 4bdd0b3

Please sign in to comment.