All Products
Search
Document Center

Alibaba Cloud Service Mesh:Custom request headers and response headers

Last Updated:Feb 28, 2024

In Service Mesh (ASM), both VirtualService and EnvoyFilter can be used to customize request headers and response headers. However, their use scenarios and flexibility are different. This topic describes the differences between customizing request and response headers by using VirtualService and EnvoyFilter CustomResourceDefinitions (CRDs).

Comparison between VirtualService and EnvoyFilter

VirtualService is more suitable for modifying simple, routing-related request and response headers, whereas EnvoyFilter provides the ability to deeply customize Envoy proxies. You can choose between them based on your business requirements and the comparisons in the following table.

Item

VirtualService

EnvoyFilter

Abstraction level

Provides a higher-level abstraction that allows you to directly define the addition or removal of request headers and response headers in routing rules of Istio. These routing rules are easier to understand and define and are the recommended way to configure request headers and response headers.

Provides a lower-level interface that allows you to directly manage the configurations of Envoy proxies. Envoyfilter allows you to write custom Lua scripts or use other Envoy extensions to implement complex logic. This method is more powerful and flexible, but also more complex. It requires a deeper understanding of Envoy configurations.

Usability

Follows CRDs of Istio for easier configuration and understanding.

Features complex configuration and requires a good understanding of the internal working principles of Envoy. To correctly write an Envoy filter, you must be familiar with the Envoy configuration API. Therefore, errors are more likely to occur.

Applicable scope

VirtualService can meet most common header operation requirements, such as simple addition, modification, or deletion of request headers and response headers. For example, it allows you to set header values to fixed static strings. In addition, it can dynamically generate request and response header values by using built-in expressions. These expressions are usually enclosed in the % symbol and can reference different dynamic content such as request attributes. All HTTP command operators used to access logs can be specified in custom request or response headers. For example, %UPSTREAM_CLUSTER% indicates the name of a service provider. For more information, see Command Operators.

EnvoyFilter supports advanced customization and complex operations that cannot be implemented by VirtualService, such as performing condition checks, complex data transformations, or calling external services. Custom values of request and response headers can be dynamic values that are implemented through code.

Use scenarios

ASM needs to only add, remove, or modify headers in requests or responses, and these operations are associated with specific routing rules.

ASM needs to perform in-depth request or response operations, or needs to change headers globally without modifying routing rules of Istio.

References