I'm trying to use a lua HTTP filter to set a response header whose value depends on a request header.
As a simple example, suppose we want to copy a header from the request to the response. How can we do this using a lua filter?
Maybe we can store the request header in a "global" table during envoy_on_request and read it later when envoy_on_response is called. However, even if this approach makes sense, how can we correlate responses with requests to be able to do this?
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.
This will be very helpful.
One use case for this:
datawire/ambassador#1847
Could we please reopen this as it's an excellent use case?
For example; we wish to write a response handler which logs information about the request in error scenarios!
see the example here:
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#set
it stores headers in dynamic metadata in the request handler which are then available in the response handler
see the example here:
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#set
it stores headers in dynamic metadata in the request handler which are then available in the response handler
@vbuciuc Works for me. But the filterName in dynamicMetadata:set(filterName, key, value) confuses me. I have my own http filter named my-filter. Which name should I use, my-filter, my-filter.lua or envoy.filters.http.lua? In addition, is the data stored in a lua file?
@ErikXu sorry for confusing docs and late reply. So the filterName can be anything, think about a namespace (we need to update the docs).
As an example:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.config.filter.http.lua.v2.Lua
inline_code: |
function envoy_on_request(request_handle)
request_handle:streamInfo():dynamicMetadata():set("context", "foo", "bar")
end
function envoy_on_response(response_handle)
local foo = response_handle:streamInfo():dynamicMetadata():get("context")["foo"]
response_handle:logInfo(foo)
end
Most helpful comment
This will be very helpful.
One use case for this:
datawire/ambassador#1847