jakubdyszkiewicz / envoy-http-filter-pass-header

PoC I did on my training days - pass additional headers with passing only x-request-id

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Envoy filter example

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.

Building

To build the Envoy static binary:

  1. git submodule update --init
  2. bazel build //http-filter-example:envoy

Testing

To run the sample integration test:

bazel test //http-filter-example:http_filter_integration_test

How it works

See the network filter example.

How to write and use an HTTP filter

  • The main task is to write a class that implements the interface Envoy::Http::StreamDecoderFilter as in http_filter.h and http_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 implement Envoy::Http::StreamEncoderFilter or Envoy::Http::StreamFilter instead.
  • You also need a class that implements Envoy::Server::Configuration::NamedHttpFilterConfigFactory to enable the Envoy binary to find your filter, as in http_filter_config.cc. It should be linked to the Envoy binary by modifying BUILD 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!
  config:
    key: via
    val: sample-filter
- name: envoy.router
  config: {}

About

PoC I did on my training days - pass additional headers with passing only x-request-id


Languages

Language:C++ 88.2%Language:Starlark 11.8%