Skip to content

Commit

Permalink
[proxy] fix accessing undefined variable
Browse files Browse the repository at this point in the history
with a regression test
  • Loading branch information
mikz committed Mar 20, 2017
1 parent 75df289 commit 5726592
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- `http_ng` client supports auth passsed in the url, and default client options if the request options are missing for methods with body (POST, PUT, etc.) [PR #310](https://github.com/3scale/apicast/pull/310)
- Fixed lazy configuration loader to recover from failures [PR #313](https://github.com/3scale/apicast/pull/313)
- Fixed undefined variable `p` in post\_action [PR #316](https://github.com/3scale/apicast/pull/316)

### Removed

Expand Down
22 changes: 15 additions & 7 deletions apicast/src/apicast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ end
function _M:rewrite()
ngx.on_abort(_M.cleanup)

ngx.var.original_request_id = ngx.var.request_id

local host = ngx.var.host
-- load configuration if not configured
-- that is useful when lua_code_cache is off
Expand All @@ -65,18 +67,24 @@ end

function _M.post_action()
local request_id = ngx.var.original_request_id
local p = post_action_proxy[request_id]
post_action_proxy[request_id] = nil
p:post_action()
local p = ngx.ctx.proxy or post_action_proxy[request_id]

if p then
p:post_action()
else
ngx.log(ngx.INFO, 'could not find proxy for request id: ', request_id)
end
end

function _M.access()
local p = ngx.ctx.proxy
local fun = p:call() -- proxy:access() or oauth handler
local request_id = ngx.var.request_id
post_action_proxy[request_id] = p
ngx.var.original_request_id = request_id
return fun()

local ok, err = fun()

post_action_proxy[ngx.var.original_request_id] = p

return ok, err
end

_M.body_filter = noop
Expand Down
2 changes: 1 addition & 1 deletion apicast/src/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ local function find_service_strict(self, host)
if found then break end
end

return found or ngx.log(ngx.ERR, 'service not found for host ', host)
return found or ngx.log(ngx.WARN, 'service not found for host ', host)
end

local function find_service_cascade(self, host)
Expand Down
14 changes: 13 additions & 1 deletion t/003-apicast.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GET /?user_key=value
no mapping rules!
--- error_code: 412
--- error_log
skipping after action, no cached key
could not find proxy for request
=== TEST 3: authentication credentials invalid
The message is configurable and default status is 403.
Expand Down Expand Up @@ -517,3 +517,15 @@ all ok
$::dns->("localhost.example.com", "127.0.0.1")
--- no_error_log
[error]
=== TEST 15: invalid service
The message is configurable and default status is 403.
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
--- config
include $TEST_NGINX_APICAST_CONFIG;
--- request
GET /?user_key=value
--- error_code: 404
--- no_error_log
[error]

0 comments on commit 5726592

Please sign in to comment.