Modify incoming response headers

更新时间:
复制 MD 格式

After a user request reaches your origin server through DCDN, you can modify the HTTP response headers sent by the origin server. This allows you to add specific capabilities or ensure that responses conform to custom rules, such as caching policies, MIME types, or expiration times.

Prerequisites

This feature is not enabled by default. To use this feature for a domain name, you must submit a ticket to enable it.

Background

An HTTP (Hypertext Transfer Protocol) response header is a component in the header of an HTTP response. By modifying incoming response headers, you can add specific functionalities to the response. A response header consists of a name, a colon (:), and a value. For example, Cache-Control: no-cache.

HTTP uses a request-response model. When a user sends a request, it is routed through DCDN to the origin server. The origin server then sends a response. You can modify the headers of this response to implement custom logic. The following figure shows the process.

image

Alibaba Cloud provides the following response header parameters to implement the capabilities described in the following table.

Response header

Description

Example

Cache-Control

Controls how clients and DCDN points of presence (POPs) cache the object. For example, the max-age directive sets the cache duration in seconds.

Cache-Control: max-age=3600

Content-Type

Specifies the MIME type of the response body.

Content-Type: application/x-www-form-urlencoded

Expires

Specifies a date and time after which the response is considered expired.

Expires: Wed, 21 Oct 2025 07:28:00 GMT

Last-Modified

Indicates the date and time when the requested object was last modified.

Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT

Custom Response Header

If the standard headers do not meet your requirements, select Custom Response Header to define custom header names and values.

Examples: Allow, Content-Encoding, and Content-Length.

Note
  • An origin-pull request is an HTTP message sent from a DCDN point of presence (POP) to an origin server for a specific accelerated domain.

  • Active rules apply to all responses for resources under the domain. These rules affect only responses from the origin server to DCDN POPs, not responses from a POP to a user.

  • Wildcard domain names are not supported.

Procedure

  1. Log on to the DCDN console.

  2. In the left-side navigation pane, click Domain Names.

  3. On the Domain Names page, find the domain name that you want to manage and click Configure in the Actions column.

  4. In the domain's navigation pane, click Origin Fetch.

  5. Click the Modify Incoming Response Header tab.

  6. On the Modify Incoming Response Header tab, click Add.

  7. Configure the incoming response header rule.

    You can add, replace, modify, or delete HTTP headers. This applies to default headers, previously added headers, or headers that are no longer required.

    Note
    • If you configure multiple operations for the same response header, they are executed in the following order of priority: Replace > Add > Modify > Delete. For example, if you configure both an Add and a Delete operation for the same header, the header is first added and then deleted.

    • If you use this feature within the rule engine, the rule's priority determines the execution order, not the operation priority described in this topic.

    • Add a response header

      HTTP响应头

      Parameter

      Example

      Description

      Operation

      Add

      Adds the specified header to the response from the origin server.

      Response Header Parameter

      Custom Response Header

      You can select a preset header parameter from the drop-down list, or select Custom Response Header to configure a custom header parameter.

      Custom Header Name

      x-code

      Specifies the custom header name as x-code.

      Header Value

      key1

      You can specify multiple values for a single header. Separate values with commas (,).

      key1,key2

      Allow Duplicates

      Yes

      When Allow Duplicates is set to Allow, you can set different values for the response header parameter. For example: x-code:key1, x-code:key2.

      No

      When Allow Duplicates is set to Do not allow, the response header parameter can have only a unique value. A new value overwrites the previous one. For example, if you first add x-code:key1 and then add x-code:key2, the final value is x-code:key2.

    • Replace a response header

      替换

      Parameter

      Example

      Description

      Operation

      Replace

      The Replace operation is only allowed for headers that appear once. This operation is not allowed if the specified header is duplicated.

      Response Header Parameter

      Custom Response Header

      You can select a preset header parameter from the drop-down list, or select Custom Response Header to replace a custom header parameter.

      Custom Header Name

      x-code

      Specifies the custom header name as x-code.

      Find

      key

      A regular expression to find the content within the header value that you want to replace.

      Replace With

      abc

      The replacement value for the matched content.

      Match

      Match All

      When the Match option is set to Match All, all matched values are replaced. For example, if you replace the value key that is matched by a regular expression with abc in x-code:key1,key2,key3, the result is x-code:abc1,abc2,abc3.

      Match the First Only

      When the Match option is set to Match only the first, only the first matched value is replaced. For example, if you replace the matched value 'key' with 'abc' in x-code:key1,key2,key3, the result is x-code:abc1,key2,key3.

    • Modify a response header

      变更

      Parameter

      Example

      Description

      Operation

      Modify

      The Modify operation is only allowed for headers that appear once. This operation is not allowed if the specified header is duplicated.

      Response Header Parameter

      Custom Response Header

      You can select a preset header parameter from the drop-down list, or select Custom Response Header to modify a custom header parameter.

      Custom Header Name

      x-code

      Specifies the custom header name as x-code.

      Modify To

      key1,key3

      The new value for the header. You can specify multiple values, separated by commas (,).

    • Delete a response header

      删除

      Parameter

      Example

      Description

      Operation

      Delete

      Deletes all instances of the specified header, regardless of whether duplicates exist.

      Response Header Parameter

      Custom Response Header

      You can select a preset header parameter from the drop-down list, or select Custom Response Header to delete a custom header parameter.

      Custom Header Name

      x-code

      Specifies the custom header name as x-code.

  8. Click OK.