Skip to content

Commit

Permalink
[policy] trigger post_action phase
Browse files Browse the repository at this point in the history
sharing context to post_action enables executing the phase
with all context from the main request - including policy chain
  • Loading branch information
mikz committed Jan 4, 2018
1 parent 19b3a9b commit 65436c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix loading renamed APIcast code [PR #525](https://github.com/3scale/apicast/pull/525)
- Fix `apicast` command when installed from luarocks [PR #527](https://github.com/3scale/apicast/pull/527)
- Fix lua docs formatting in the CORS policy [PR #530](https://github.com/3scale/apicast/pull/530)
- `post_action` phase not being called in the policy_chain [PR #539](https://github.com/3scale/apicast/pull/539)

## Changed

Expand All @@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Extract Test::APIcast to own package on CPAN [PR #528](https://github.com/3scale/apicast/pull/528)
- Load policies by the APIcast loader instead of changing load path [PR #532](https://github.com/3scale/apicast/pull/532), [PR #536](https://github.com/3scale/apicast/pull/536)
- Add `src` directory to the Lua load path when using CLI [PR #533](https://github.com/3scale/apicast/pull/533)
- `post_action` phase now shares `ngx.ctx` with the main request [PR #539](https://github.com/3scale/apicast/pull/539)

## [3.2.0-alpha2] - 2017-11-30

Expand Down
12 changes: 10 additions & 2 deletions gateway/conf.d/apicast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ location @out_of_band_authrep_action {

set_by_lua $original_request_time 'return ngx.var.request_time';

content_by_lua_block { require('apicast.executor'):post_action() }
content_by_lua_block {
require('resty.ctx').apply()
require('apicast.executor'):post_action()
}

log_by_lua_block {
ngx.var.post_action_impact = ngx.var.request_time - ngx.var.original_request_time
Expand All @@ -70,12 +73,17 @@ location / {
set $version '';
set $real_url null;

set $ctx_ref -1;

set $post_action_impact null;
set $original_request_id null;

proxy_ignore_client_abort on;

rewrite_by_lua_block { require('apicast.executor'):rewrite() }
rewrite_by_lua_block {
require('resty.ctx').stash()
require('apicast.executor'):rewrite()
}
access_by_lua_block { require('apicast.executor'):access() }
body_filter_by_lua_block { require('apicast.executor'):body_filter() }
header_filter_by_lua_block { require('apicast.executor'):header_filter() }
Expand Down
1 change: 1 addition & 0 deletions t/apicast-policy-chains.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ running phase: access
running phase: balancer
running phase: header_filter
running phase: body_filter
running phase: post_action
4 changes: 2 additions & 2 deletions t/apicast.t
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Content-Type: text/plain; charset=utf-8
no mapping rules!
--- error_code: 404
--- error_log
could not find proxy for request
skipping after action, no cached key

=== TEST 5: no mapping rules matched configurable error
The message is configurable and status also.
Expand Down Expand Up @@ -136,7 +136,7 @@ GET /?user_key=value
no mapping rules!
--- error_code: 412
--- error_log
could not find proxy for request
skipping after action, no cached key

=== TEST 6: authentication credentials invalid default error
There are defaults defined for the error message, the content-type, and the
Expand Down

0 comments on commit 65436c0

Please sign in to comment.