Lua filter

    Sandbox environment

    Setup your sandbox environment with Docker and Docker Compose, and clone the Envoy repository with Git.

    Used to make requests.

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

    • envoy_on_request(request_handle)

    • envoy_on_response(response_handle)

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

    Change to the examples/lua directory.

    Step 2: Send a request to the service

    The output from the curl command below should include the headers foo.

    1. $ curl -v localhost:8000
    2. Trying ::1...
    3. * TCP_NODELAY set
    4. * Connected to localhost (::1) port 8000 (#0)
    5. > GET / HTTP/1.1
    6. > Host: localhost:8000
    7. > User-Agent: curl/7.64.1
    8. > Accept: */*
    9. >
    10. < HTTP/1.1 200 OK
    11. < content-length: 544
    12. < etag: W/"220-IhsqVTh4HjcpuJQ3C+rEL1Cw1jA"
    13. < date: Thu, 31 Oct 2019 03:13:24 GMT
    14. < x-envoy-upstream-service-time: 1
    15. < response-body-size: 544 <-- This is added to the response header by our Lua script. --<
    16. < server: envoy
    17. <
    18. {
    19. "path": "/",
    20. "headers": {
    21. "host": "localhost:8000",
    22. "user-agent": "curl/7.64.1",
    23. "accept": "*/*",
    24. "x-forwarded-proto": "http",
    25. "x-request-id": "a78fcce7-2d67-4eeb-890a-73eebb942a17",
    26. "content-length": "0"
    27. },
    28. "method": "GET",
    29. "body": "",
    30. "fresh": false,
    31. "hostname": "localhost",
    32. "ip": "::ffff:172.20.0.2",
    33. "ips": [],
    34. "protocol": "http",
    35. "query": {},
    36. "subdomains": [],
    37. "xhr": false,
    38. "os": {
    39. "hostname": "7ca39ead805a"
    40. }

    See also

    Learn more about the Envoy Lua filter.

    Lua

    The Lua programming language.