From 65436c069b21c7d326359a9390c7c247159c1b42 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Thu, 4 Jan 2018 11:07:50 +0100 Subject: [PATCH] [policy] trigger post_action phase sharing context to post_action enables executing the phase with all context from the main request - including policy chain --- CHANGELOG.md | 2 ++ gateway/conf.d/apicast.conf | 12 ++++++++++-- t/apicast-policy-chains.t | 1 + t/apicast.t | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 446e4f77d..d59c4a95d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/gateway/conf.d/apicast.conf b/gateway/conf.d/apicast.conf index 10acee1aa..2fc7381c4 100644 --- a/gateway/conf.d/apicast.conf +++ b/gateway/conf.d/apicast.conf @@ -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 @@ -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() } diff --git a/t/apicast-policy-chains.t b/t/apicast-policy-chains.t index ff740e3f6..69dd3daf2 100644 --- a/t/apicast-policy-chains.t +++ b/t/apicast-policy-chains.t @@ -65,3 +65,4 @@ running phase: access running phase: balancer running phase: header_filter running phase: body_filter +running phase: post_action diff --git a/t/apicast.t b/t/apicast.t index 4f946606f..9dfc43d83 100644 --- a/t/apicast.t +++ b/t/apicast.t @@ -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. @@ -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