Lua filter

In this example, we show how the Lua filter can be used with the Envoy proxy.

The example Envoy proxy configuration includes two Lua filters that contain two different functions:

  • envoy_on_request(request_handle)

  • envoy_on_response(response_handle)

See here for an overview of Envoy’s Lua filter and documentation regarding these functions.

Step 1: Build the sandbox

Change to the examples/lua directory.

$ pwd
$ docker compose pull
$ docker compose up --build -d
$ docker compose ps

    Name                     Command               State             Ports
lua_proxy_1         / /bin ... Up      10000/tcp,>8000/tcp
lua_web_service_1   node ./index.js                Up>80/tcp

Step 2: Send a request to the service

The output from the curl command below should include the header added by the Lua filter.

Terminal 1

$ curl -v localhost:8000 2>&1 | grep Foo
Foo: bar                              <-- This is added by the common Lua filter. --<

Step 3: Using multiple Lua filters at the same time

Two Lua filters are configured in the example Envoy proxy configuration. But the second one can only work at a specific route.

The output from the curl command below should include the headers that added by multiple Lua filters.

Terminal 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. --<

See also

Envoy Lua filter

Learn more about the Envoy Lua filter.


The Lua programming language.