Lua 篩選器
在此範例中,我們示範如何將 Lua 篩選器與 Envoy 代理一起使用。
Envoy 代理組態範例包含兩個 Lua 篩選器,其中包含兩個不同的函式
envoy_on_request(request_handle)
envoy_on_response(response_handle)
請參閱此處以取得 Envoy Lua 篩選器的概述,以及關於這些函式的文件。
步驟 1:建立沙箱
變更至 examples/lua
目錄。
$ pwd
envoy/examples/lua
$ docker compose pull
$ docker compose up --build -d
$ docker compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------
lua_proxy_1 /docker-entrypoint.sh /bin ... Up 10000/tcp, 0.0.0.0:8000->8000/tcp
lua_web_service_1 node ./index.js Up 0.0.0.0:8080->80/tcp
步驟 2:傳送請求至服務
下方 curl
命令的輸出應包含 Lua 篩選器新增的標頭。
終端機 1
$ curl -v localhost:8000 2>&1 | grep Foo
Foo: bar <-- This is added by the common Lua filter. --<
步驟 3:同時使用多個 Lua 篩選器
在 Envoy 代理組態範例中設定了兩個 Lua 篩選器。但是第二個篩選器只能在特定的路由上運作。
下方 curl
命令的輸出應包含多個 Lua 篩選器新增的標頭。
終端機 1
curl -v localhost:8000/multiple/lua/scripts 2>&1 | grep header_key_1
< header_key_1: header_value_1 <-- This is added by the second route-specific Lua filter. --<
另請參閱
- Envoy Lua 篩選器
深入了解 Envoy Lua 篩選器。
- Lua
Lua 程式設計語言。