-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest-response-print-demo.yaml
54 lines (53 loc) · 2.13 KB
/
request-response-print-demo.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: request-response-filter
namespace: gcp
spec:
configPatches:
- applyTo: HTTP_FILTER
match:
context: ANY
listener:
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_BEFORE
value:
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
function envoy_on_request(request_handle)
local headers = request_handle:headers()
local headersMap = {}
for key, value in pairs(headers) do
headersMap[key] = value
end
request_handle:streamInfo():dynamicMetadata():set("envoy.lua","request_headers",headersMap)
local requestBody = ""
for chunk in request_handle:bodyChunks() do
if (chunk:length() > 0) then
requestBody = requestBody .. chunk:getBytes(0, chunk:length())
end
end
request_handle:streamInfo():dynamicMetadata():set("envoy.lua","request_body",requestBody)
end
function envoy_on_response(response_handle)
local headers = response_handle:headers()
local headersMap = {}
for key, value in pairs(headers) do
headersMap[key] = value
end
response_handle:streamInfo():dynamicMetadata():set("envoy.lua","response_headers",headersMap)
local responseBody = ""
for chunk in response_handle:bodyChunks() do
if (chunk:length() > 0) then
responseBody = responseBody .. chunk:getBytes(0, chunk:length())
end
end
response_handle:streamInfo():dynamicMetadata():set("envoy.lua","response_body",responseBody)
end