Skip to content

Commit 6f8bc94

Browse files
committed
fix(e2e): simplify lua filter context script to use response_handle:filterContext() directly
The previous script had a nil-value bug: - ctx["custom_value"] returns nil when filterContext() wraps an empty struct - Storing nil via dynamicMetadata and then using it in headers():add() caused a silent Lua error, so the response header was never set Fix by calling response_handle:filterContext() directly in envoy_on_response, which is available on both request and response handles per Envoy's C++ source. Also add a nil guard for val before calling headers():add() to be safe. Signed-off-by: Norman Stetter <85173861+norman-zon@users.noreply.github.com>
1 parent 414db72 commit 6f8bc94

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

test/e2e/testdata/lua-http.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ metadata:
8989
namespace: gateway-conformance-infra
9090
data:
9191
lua: |
92-
function envoy_on_request(request_handle)
93-
local ctx = request_handle:filterContext()
94-
if ctx ~= nil then
95-
request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua", "custom_value", ctx["custom_value"])
96-
end
97-
end
9892
function envoy_on_response(response_handle)
99-
local meta = response_handle:streamInfo():dynamicMetadata():get("envoy.filters.http.lua")
100-
if meta ~= nil then
101-
response_handle:headers():add("X-Lua-Filter-Context", meta["custom_value"])
93+
local ctx = response_handle:filterContext()
94+
if ctx ~= nil then
95+
local val = ctx["custom_value"]
96+
if val ~= nil then
97+
response_handle:headers():add("X-Lua-Filter-Context", tostring(val))
98+
end
10299
end
103100
end
104101
---

0 commit comments

Comments
 (0)