-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Accessing request headers in envoy_on_response (lua HTTP filter). #4613
Comments
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. |
Could we please reopen this as it's an excellent use case? |
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 |
1 similar comment
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 |
@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
|
@dio I have this filter and it doesn't seem to be working
|
@dio is it possible to get SIDECAR_INBOUND request headers and pass it to SIDECAR_OUTBOUND envoy_on_request() ? |
@Arsen-Uulu i do it by storing them on the dynamic metadata, similar to how you've done it, but i build up a map first
|
@Stono Hey than you for suggestion. What I want is capture req_headers from upstream and when my app makes a new request(outbound) I wanna add that header that I captured from inbound request |
Hum, seems like you need your service to collaborate? Unless you call it directly using https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#httpcall (not sure if that is what you want). |
change context to envoy.lua |
I found the docs exceptionally unhelpful, but I'm really pleased to have eventually stumbled across this thread! For the next poor soul, I warmly recommend making it clearer to new users like myself that the header_to_metadata_filter's "namespace" field needs to be the name of the filter that uses it, and ask that you provide an example of chaining a header -> metadata -> lua handler. It might even be worthwhile linking that documentation to the set / get example. Thanks again! |
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 whenenvoy_on_response
is called. However, even if this approach makes sense, how can we correlate responses with requests to be able to do this?The text was updated successfully, but these errors were encountered: