Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid: Available context move to readwrite linked list. #1107

Merged
merged 1 commit into from
Aug 23, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion gateway/src/apicast/template_string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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),
Expand Down
59 changes: 59 additions & 0 deletions t/apicast-policy-headers.t
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we limit the number of allocations using the liquid lib? Otherwise, this might not be safe.
Ref:

-- Set resource limits to avoid loops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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]