This project demonstrates the linking of additional HTTP filters with the Envoy binary.
A new filter sample
which adds a HTTP header is introduced.
Integration tests demonstrating the filter's end-to-end behavior are
also provided.
To build the Envoy static binary:
git submodule update --init
bazel build //http-filter-example:envoy
To run the sample
integration test:
bazel test //http-filter-example:http_filter_integration_test
See the network filter example.
- The main task is to write a class that implements the interface
Envoy::Http::StreamDecoderFilter
as inhttp_filter.h
andhttp_filter.cc
, which contains functions that handle http headers, data, and trailers. Note that this is an example of decoder filters, and to write encoder filters or decoder/encoder filters you need to implementEnvoy::Http::StreamEncoderFilter
orEnvoy::Http::StreamFilter
instead. - You also need a class that implements
Envoy::Server::Configuration::NamedHttpFilterConfigFactory
to enable the Envoy binary to find your filter, as inhttp_filter_config.cc
. It should be linked to the Envoy binary by modifyingBUILD
file. - Finally, you need to modify the Envoy config file to add your filter to the
filter chain for a particular HTTP route configuration. For instance, if you
wanted to change the front-proxy example to chain our
sample
filter, you'd need to modify its config to look like
http_filters:
- name: sample # before envoy.router because order matters!
typed_config:
"@type": type.googleapis.com/sample.Decoder
key: via
val: sample-filter
- name: envoy.router
typed_config: {}