我有一个特使 lua 过滤器来拦截上游响应并从 lua 过滤器的“envoy_on_response”方法调用外部 api。我需要 envoy_on_response()" 协程中 request_handle 的 "授权" 值并将其传递给外部 api 调用。我目前正在做如下:
- 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
在特使文档中的某些地方,提到“envoy_on_request()”和“envoy_on_response()”都被称为协同程序,它们之间不应共享任何内容。所以,我的问题是,在“envoy_on_response()”中获取和传递“授权”标头的正确方法是什么?
谢谢。