-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-body-json-parse.yml
39 lines (39 loc) · 1.34 KB
/
04-body-json-parse.yml
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
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: body-json-parse
namespace: sock-shop
spec:
workloadSelector:
labels:
name: front-end
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
portNumber: 8079
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
JSON = (loadfile "/var/lib/lua/JSON.lua")()
function envoy_on_request(request_handle)
request_handle:logCritical("Hello World 14")
local body_obj = request_handle:body()
if body_obj ~= nil then
local body_bytes = body_obj:getBytes(0, body_obj:length())
request_handle:logCritical("Body:"..body_bytes)
local raw_json_text = tostring(body_bytes)
local lua_value = JSON:decode(raw_json_text)
request_handle:logCritical("Body:"..tostring(lua_value["id"]))
end
end