如何将数据放入 EnvoyFilter 拦截的请求体中?

How to put data into request body intercepted on EnvoyFilter?

我正在尝试这个,但是没有用,也没有显示任何错误。

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: eva-decrypt-data
  namespace: eva
spec:
  configPatches:
    - applyTo: HTTP_FILTER
      match:
        context: ANY
        listener:
          filterChain:
            filter:
              name: "envoy.http_connection_manager"
      patch:
        operation: INSERT_BEFORE
        value:
          name: envoy.lua
          typed_config:
            "@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
            inlineCode: |
              function envoy_on_request(request_handle)
               local buffered = request_handle:body()
               buffered:setBytes("new body data")

根据评论发布社区 Wiki,以提高可见度。随意扩展它。


问题已解决。函数 request_handle:body():setBytes("") 仅适用于 1.10 以上的 Istio 版本:

The problem was istio version, request_handle:body():setBytes("") works only above 1.10