envoyproxy / envoy-filter-example

Example of consuming Envoy and adding a custom filter
331 stars 204 forks source link

Parser exploration #176

Closed tnawathe21 closed 1 year ago

tnawathe21 commented 1 year ago

Description

This PR modifies the Envoy HTTP filter plugin to perform a basic set-header operation. For example, the following config will modify the x-forwarded-proto header to have the value https.

- name: sample
            typed_config:
              "@type": type.googleapis.com/sample.Decoder
              key: header-processing
              val: "set-header x-forwarded-proto https"

Testing

// Build and run envoy
bazel build //http-filter-example:envoy
./bazel-bin/http-filter-example/envoy -c ./http-filter-example/envoy-sample-config.yaml

// Set up Docker backend to echo http headers and send a curl request to envoy
// Docker image found here: https://hub.docker.com/r/ealen/echo-server
curl localhost:8081

We can see the specified header is set to https:

ubuntu@ip-10-128-172-195:~$ curl localhost:8081
{"host":{"hostname":"localhost","ip":"::ffff:172.17.0.1","ips":[]},"http":{"method":"GET","baseUrl":"","originalUrl":"/","protocol":"http"},"request":{"params":{"0":"/"},"query":{},"cookies":{},"body":{},"headers":{"host":"localhost:8081","user-agent":"curl/7.68.0","accept":"*/*","x-request-id":"9892ce28-2945-4d3e-8eb0-ab4695cf696d","x-forwarded-proto":"https","x-envoy-expected-rq-timeout-ms":"15000"}},"environment":{"PATH":"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOSTNAME":"e6cf43c557fd","NODE_VERSION":"16.16.0","YARN_VERSION":"1.22.19","HOME":"/root"}}