You can configure a header setting policy to modify the headers in requests or responses before the requests are forwarded to destination backend services or before the responses of backend services are returned to clients. This topic describes how to configure a header setting policy for a cloud-native gateway.
Configure a header setting policy
Log on to the MSE console. In the top navigation bar, select a region.
In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the name of the gateway.
In the left-side navigation pane, click Routes, and click the Routes tab.
Find the routing rule that you want to modify and click Policies in the Actions column.
In the left-side navigation pane of the Policies tab, click Headers. On the Edit Header tab, click or Add Rule on the right side.
Configure the parameters and click Save in the upper-right corner.
Parameter
Description
Header Type
The header type.
Request: The header setting policy takes effect for requests.
Response: The header setting policy takes effect for responses.
Action Type
The header-related operation that you can perform on requests or responses.
Add: adds a header to requests or responses.
NoteIf the specified header already exists in a request or a response, the specified header value in this policy is concatenated to the existing header value. The values are separated by commas (,).
Modify: modifies a header in requests or responses.
NoteIf the specified header does not exist in a request or a response, the header is added to the request or response based on the header key and value specified in this rule.
If the specified header already exists, its value is overwritten by the specified header value in this rule.
Delete: removes a header from requests or responses.
Header Key
The name of the header in requests or responses.
Header Value
The value of the header in requests or responses.
After the header setting policy is configured, turn on Enable.
If you enable the header setting policy, the gateway controls the headers in requests or responses.
If you disable the header setting policy, the gateway does not control the headers in requests or responses.
Verify the result
In this example, a header is added to responses. The following figure shows the configuration of the policy.
Run the following command to send a test request:
curl -I http://121.196.XX.XX/demo/item/list // The ingress IP address of the gateway.
The following response is returned. The response contains the
test:demo
header.HTTP/1.1 200 OK x-content-type-options: nosniff x-xss-protection: 1; mode=block cache-control: no-cache, no-store, max-age=0, must-revalidate pragma: no-cache expires: 0 x-frame-options: DENY content-type: application/json content-length: 86 date: Tue, 30 Nov 2021 03:03:04 GMT x-envoy-upstream-service-time: 4 test: demo server: istio-envoy