diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9ed0fde..890dddc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Option to load service configurations one by one lazily [PR #1099](https://github.com/3scale/APIcast/pull/1099) - New maintenance mode policy, useful for maintenance periods. [PR #1105](https://github.com/3scale/APIcast/pull/1105), [THREESCALE-3189](https://issues.jboss.org/browse/THREESCALE-3189) - Remove dnsmasq process for APIcast [PR #1090](https://github.com/3scale/APIcast/pull/1090), [THREESCALE-1555](https://issues.jboss.org/browse/THREESCALE-1555) +- Allow to use capture function in liquid templates. [PR #1107](https://github.com/3scale/APIcast/pull/1107), [THREESCALE-1911](https://issues.jboss.org/browse/THREESCALE-1911) ## [3.6.0-rc1] - 2019-07-04 diff --git a/gateway/src/apicast/template_string.lua b/gateway/src/apicast/template_string.lua index 3afd35254..90a9bf437 100644 --- a/gateway/src/apicast/template_string.lua +++ b/gateway/src/apicast/template_string.lua @@ -10,6 +10,7 @@ local format = string.format local pcall = pcall local ngx_variable = require('apicast.policy.ngx_variable') +local LinkedList = require('apicast.linked_list') local _M = {} @@ -102,7 +103,8 @@ function LiquidTemplateString.new(string) end function LiquidTemplateString:render(context) - local available_context = ngx_variable.available_context(context) + + local available_context = LinkedList.readwrite({}, ngx_variable.available_context(context)) return Liquid.Interpreter:new(self.parser):interpret( LiquidInterpreterContext:new(available_context), diff --git a/t/apicast-policy-headers.t b/t/apicast-policy-headers.t index 2bd5b535a..70266d44b 100644 --- a/t/apicast-policy-headers.t +++ b/t/apicast-policy-headers.t @@ -723,3 +723,62 @@ yay, api backend --- no_error_log [error] oauth failed with + +=== TEST 12: Liquid validate capture works +Validate that capture function works correctly THREESCALE-1911 +--- backend + location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } + } +--- configuration +{ + "services": [ + { + "id": 42, + "backend_version": 1, + "backend_authentication_type": "service_token", + "backend_authentication_value": "token-value", + "proxy": { + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 } + ], + "policy_chain": [ + { "name": "apicast.policy.apicast" }, + { + "name": "apicast.policy.headers", + "configuration": + { + "request": + [ + { + "op": "set", + "header": "New-Header-1", + "value": "{% capture foo%}bar{% endcapture%}{{foo}}", + "value_type": "liquid" + } + ] + } + } + ] + } + } + ] +} +--- upstream + location / { + content_by_lua_block { + local assert = require('luassert') + assert.same("bar", ngx.req.get_headers()['New-Header-1']) + ngx.say('yay, api backend'); + } + } +--- request +GET /?user_key=value +--- response_body +yay, api backend +--- error_code: 200 +--- no_error_log +[error]