I have a envoy lua filter to intercept upstream response and call a external api from the lua filter's "envoy_on_response" method. I need request_handle's "authorization" value inside envoy_on_response()" coroutine and pass it to external api call. I'm doing currently as below:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
local authToken = ""
-- Called on the request path.
function envoy_on_request(request_handle)
authToken = request_handle:headers():get("authorization")
end
-- Called on the response path.
function envoy_on_response(response_handle)
-- Make an HTTP call to an upstream host with the following headers, body, and timeout.
local headers, body = response_handle:httpCall(
"ext_authz-http-service",
{
[":method"] = "GET",
[":path"] = "/v1/response-filter",
[":authority"] = "my-api-service",
["authorization"] = authToken
},
"test body data",
5000)
end
Some where in the envoy doc, it was mentioned both "envoy_on_request()" & "envoy_on_response()" are called as co-routines and nothing should be shared between them. So, my question is, what is the right way to get and pass "authorization" header inside "envoy_on_response()" ?.
Thanks.