Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions gateway/src/apicast/configuration/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,21 @@ end
-- @return @{credentials_v1}, @{credentials_v2}, or @{credentials_oauth}
-- @return[opt] error message why credentials could not be extracted
function _M:extract_credentials()
local backend_version = tostring(self.backend_version)
local credentials = rawget(self, 'credentials')

if not credentials then
return nil, 'missing credentials'
end

local extractor = backend_version_credentials['version_' .. backend_version]
local extractor = self.credentials_extractor

if not extractor then
return nil, 'invalid backend version: ' .. backend_version
local backend_version = tostring(self.backend_version)
extractor = backend_version_credentials['version_' .. backend_version]
if not extractor then
return nil, 'invalid backend version: ' .. backend_version
end
self.credentials_extractor = extractor
end

return extractor(credentials)
Expand Down
7 changes: 4 additions & 3 deletions gateway/src/apicast/mapping_rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ local function matches_querystring_params(params, args)
return match
end

local function matches_uri(rule_pattern, uri)
return re_match(uri, format("^%s", rule_pattern), 'oj')
local function matches_uri(anchored_pattern, uri)
return re_match(uri, anchored_pattern, 'oj')
end

local function new(http_method, pattern, params, querystring_params, metric, delta, last, owner_id, owner_type)
Expand All @@ -97,6 +97,7 @@ local function new(http_method, pattern, params, querystring_params, metric, del
self.method = http_method
self.pattern = pattern
self.regexpified_pattern = regexpify(pattern)
self.anchored_pattern = format("^%s", self.regexpified_pattern)
self.parameters = params
self.system_name = metric or error('missing metric name of rule')
self.delta = delta
Expand Down Expand Up @@ -152,7 +153,7 @@ end
-- @treturn boolean Whether the mapping rule matches the given request.
function _M:matches(method, uri, args)
local match = (self.method == self.any_method or self.method == method) and
matches_uri(self.regexpified_pattern, uri) and
matches_uri(self.anchored_pattern, uri) and
self.querystring_params(args)

-- match can be nil. Convert to boolean.
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/apicast/policy/upstream/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function _M:rewrite(context)
local req_uri = ngx.var.uri

for _, rule in ipairs(self.rules) do
if match(req_uri, rule.regex) then
if match(req_uri, rule.regex, 'oj') then
ngx.log(ngx.DEBUG, 'upstream policy uri: ', req_uri, ' regex: ', rule.regex, ' match: true')
-- better to allocate new object for each request as it is going to get mutated
context[self] = Upstream.new(rule.url)
Expand Down
Loading