Skip to content

Commit

Permalink
Merge pull request envoyproxy#108 from helight/zh_intro-arch_overview…
Browse files Browse the repository at this point in the history
…-http-http_filters

Zh intro arch overview http http filters
  • Loading branch information
majinghe authored Nov 13, 2020
2 parents 10e2e9a + 0e54e9d commit 099158e
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions docs/root/intro/arch_overview/http/http_filters.rst
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
.. _arch_overview_http_filters:

HTTP filters
HTTP 过滤器
============

Much like the :ref:`network level filter <arch_overview_network_filters>` stack, Envoy supports an
HTTP level filter stack within the connection manager. Filters can be written that operate on HTTP
level messages without knowledge of the underlying physical protocol (HTTP/1.1, HTTP/2, etc.) or
multiplexing capabilities. There are three types of HTTP level filters:

* **Decoder**: Decoder filters are invoked when the connection manager is decoding parts of the
request stream (headers, body, and trailers).
* **Encoder**: Encoder filters are invoked when the connection manager is about to encode parts of
the response stream (headers, body, and trailers).
* **Decoder/Encoder**: Decoder/Encoder filters are invoked both when the connection manager is
decoding parts of the request stream and when the connection manager is about to encode parts of
the response stream.

The API for HTTP level filters allows the filters to operate without knowledge of the underlying
protocol. Like network level filters, HTTP filters can stop and continue iteration to subsequent
filters. This allows for more complex scenarios such as health check handling, calling a rate
limiting service, buffering, routing, generating statistics for application traffic such as
DynamoDB, etc. HTTP level filters can also share state (static and dynamic) among
themselves within the context of a single request stream. Refer to :ref:`data sharing
between filters <arch_overview_data_sharing_between_filters>` for more details. Envoy already
includes several HTTP level filters that are documented in this architecture overview as well as
the :ref:`configuration reference <config_http_filters>`.
:ref:`网络层的过滤器 <arch_overview_network_filters>` 很像,Envoy 支持了链接管理中的 HTTP 层过滤器。
可以开发过滤器处理 HTTP 层的消息,而不用知道底层的物理协议(比如,HTTP/1.1、HTTP/2)或者多路复用功能。HTTP 层
的过滤器有 3 种类型:

* **解码器**: 解码过滤器用于链接管理器解码部分请求流(分请头,正文和 trailer 信息)。
* **编码器**: 编码过滤器用于链接管理器编码部响应求流(响应头,正文和 trailer 信息)。
* **解码器/编码器**: 解码/编码过滤器同时用于链接管理器解码部分请求流和编码部分相应流。

HTTP 层过滤器的 API 可以让过滤器处理消息而不用知道底层协议。像网络层过滤器一样,HTTP 过滤器能停止和继续
处理后续的过滤器。这样可以处理更复杂的场景,比如处理健康检查,调用一个限流服务,缓存,路由,给像 DynamoDB 这样的应用
收集流量统计信息等。HTTP 层的过滤器也能在单个请求流的上下文中共享状态(静态和动态)。参考这里可以了解更多:
:ref:`过滤器间的数据共享 <arch_overview_data_sharing_between_filters>`。Envoy 已经有了几个 HTTP 层的过滤器,
这些过滤器也记录在了架构概述中 :ref:`配置参考 <config_http_filters>` 。


.. _arch_overview_http_filters_ordering:

Filter ordering
过滤器顺序
---------------

Filter ordering in the :ref:`http_filters field <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.http_filters>`
matters. If filters are configured in the following order (and assuming all three filters are
decoder/encoder filters):
过滤器顺序在 :ref:`http_filters 字段 <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.http_filters>`
中很重要。如果按照如下顺序配置过滤器(假设这 3 个过滤器都是 解码/编码过滤器):

.. code-block:: yaml
http_filters:
- A
- B
# The last configured filter has to be a terminal filter, as determined by the
# NamedHttpFilterConfigFactory::isTerminalFilter() function. This is most likely the router
# filter.
# 配置在最后的过滤器必须是一个终结过滤器,由 NamedHttpFilterConfigFactory::isTerminalFilter() 函数决定。
# 这个过滤器很可能是路由过滤器。
- C
The connection manager will invoke decoder filters in the order: ``A``, ``B``, ``C``.
On the other hand, the connection manager will invoke encoder filters in the **reverse**
order: ``C``, ``B``, ``A``.
链接管理器将会按照这样的顺序来调用 decoder filter:``A``、``B``、``C``。
另一方面,链接管理器将会以**相反**的顺序调用 encoder filter:``C``,``B``,``A``。

0 comments on commit 099158e

Please sign in to comment.