# 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](../README.md#how-it-works).
## How to write and use an HTTP filter
- The main task is to write a class that implements the interface
[`Envoy::Http::StreamDecoderFilter`][StreamDecoderFilter] as in
[`http_filter.h`](http_filter.h) and [`http_filter.cc`](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`][StreamEncoderFilter] or
[`Envoy::Http::StreamFilter`][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`](http_filter_config.cc).
It should be linked to the Envoy binary by modifying [`BUILD`][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][front-envoy.yaml] to chain our
`sample` filter, you'd need to modify its config to look like
```yaml
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: {}
```
[StreamDecoderFilter]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L300
[StreamEncoderFilter]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L413
[StreamFilter]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L462
[BUILD]: https://github.com/envoyproxy/envoy-filter-example/blob/d76d3096c4cbd647d26b44b3f801c3afbc81d3e2/http-filter-example/BUILD#L15-L18
[front-envoy.yaml]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/examples/front-proxy/front-envoy.yaml#L28
没有合适的资源?快使用搜索试试~ 我知道了~
envoy-filter-example:使用Envoy并添加自定义过滤器的示例
共25个文件
cc:6个
build:2个
md:2个
5星 · 超过95%的资源 8 下载量 93 浏览量
2021-02-09
23:38:07
上传
评论
收藏 13KB ZIP 举报
温馨提示
使节过滤器示例 该项目演示了附加过滤器与Envoy二进制文件的链接。 引入了一个新的滤波器echo2 ,对现有的滤波器进行了相同的模重命名。 还提供了证明过滤器端到端行为的集成测试。 有关其他HTTP过滤器的示例,请参见。 建造 要构建Envoy静态二进制文件: git submodule update --init bazel build //:envoy 测验 要运行echo2集成测试: bazel test //:echo2_integration_test 要从此项目运行常规的Envoy测试: bazel test @envoy//test/... 这个怎么运作 作为子模块提供。 文件将@envoy存储库映射到此本地路径。 文件引入了一个新的Envoy静态二进制目标envoy ,该目标将新的过滤器和@envoy//source/exe:envoy_main_entr
资源详情
资源评论
资源推荐
收起资源包目录
envoy-filter-example-main.zip (25个子文件)
envoy-filter-example-main
.circleci
config.yml 540B
.gitignore 35B
.bazelversion 21B
.devcontainer 19B
README.md 1KB
envoy_binary_test.sh 170B
.gitmodules 81B
echo2_config.cc 1KB
.clang-format 145B
echo2_integration_test.cc 1KB
bazel
get_workspace_status 35B
envoy
echo2_server.yaml 631B
.bazelrc 34B
echo2.cc 471B
BUILD 1KB
echo2.h 698B
WORKSPACE 567B
http-filter-example
README.md 3KB
http_filter_config.cc 2KB
http_filter.h 1KB
http_filter.proto 212B
BUILD 1KB
http_filter.cc 1KB
http_filter_integration_test.cc 2KB
ci
do_ci.sh 646B
共 25 条
- 1
鸡糟的黄医桑
- 粉丝: 24
- 资源: 4638
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1