All Products
Search
Document Center

Microservices Engine:Configure a header setting policy

Last Updated:Mar 13, 2024

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

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. In the top navigation bar, select a region.

  3. On the Gateways page, click the name of the gateway.

  4. In the left-side navigation pane, choose Routes > Route Settings.

  5. On the Route Settings page, find the routing rule that you want to modify and click Policies in the Actions column.

  6. In the Policies section of the page that appears, click the Headers tab, and click 编辑图案 on the right or Add Rule.

    If you have not configured a header setting policy, click Add Policy.

  7. Configure the parameters and click Save in the upper-right corner.

    Header设置.png

    The following table describes the parameters.

    Parameter

    Description

    Header Type

    The header type. Valid values:

    • 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. Valid values:

    • Add: adds a header to requests or responses.

      Note

      If 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.

      Note
      • If 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.

  8. 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 keep the header setting policy disabled, 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.

Header.png

  • 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