Configure Header Modification

更新时间:
复制 MD 格式

Use header modification to change headers in a request before it is routed to a backend service, or in a response before it is returned to a client. This topic explains how to configure header modification rules for a cloud-native gateway.

Procedure

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the left-side navigation pane, click Routes. Then, click the Routes tab.

  4. For the routing rule that you want to modify, click Policies in the Actions column.

  5. In the Policies section, click Header Modification, then click the 编辑图案 icon or Add Rule on the right.

  6. Configure the rule parameters and then click Save in the upper-right corner.

    Parameter

    Description

    Header Type

    Select the header type. Valid values: Request and Response.

    • Request: Modifies the headers of the incoming request.

    • Response: Modifies the headers of the outgoing response.

    Action Type

    Select the action type. Valid values: Add, Modify, and Delete.

    • Add: Adds a header to the request or response.

      Note

      If a header with the same name already exists, the new header value is appended to the existing value and separated by a comma (,).

    • Modify: Modifies a specified header in the request or response.

      Note
      • If the specified header does not exist, the system adds a new header with the specified header key and header value.

      • If the specified header exists, the system overwrites its value.

    • Delete: Deletes a specified header from the request or response.

    Header Key

    Enter the name of the header.

    Header Value

    Enter the value of the header.

  7. After you configure the header modification rule, turn on the Enable switch.

    • If enabled, the gateway modifies request and response headers according to the configured rules.

    • If disabled, the gateway does not modify request or response headers.

Result verification

As an example, assume you have configured a rule to add a test header to a response.

  • 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 response includes 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