All Products
Search
Document Center

:Configure HTTP response headers

Last Updated:Aug 14, 2024

After a request reaches your origin through Dynamic Content Delivery Network (DCDN), you can configure the response from the origin to implement specific capabilities or rewrite the headers to conform to custom rules, such as the caching mechanism, the Multipurpose Internet Mail Extensions (MIME) type, and the response expiration time. This topic describes how to configure origin HTTP response headers.

Prerequisites

The permissions to configure custom HTTP response headers have been obtained. By default, this is unavailable to external users. To request the permissions, submit a ticket.

Background information

HTTP response headers are a component of the header section in response messages that are transmitted over HTTP. After an HTTP response header is configured, you can use parameters to pass information to the receiver. A response header consists of a domain name, a colon (:), and a value. Example: Cache-Control: no-cache.

HTTP follows a request-response model. After a request reaches the origin through DCDN, the origin responds with a status line. You can modify the response as needed. The following figure show how it works.

回源响应

The following table describes the origin parameters you can use in a response.

Response header

Description

Example

Cache-Control

Controls whether all caching mechanisms in the origin server and DCDN can cache the object. Unit: seconds.

Cache-Control: max-age=3600

Content-Type

Sets the MIME type for the request body (used for POST and PUT requests).

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

Expires

Specifies a date or time after which the response expires.

Content-Type: text/html

Last-Modified

Queries the date when the requested object is last modified.

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

Custom HTTP Response Header

If the preceding response headers cannot meet your requirements, you can also select Custom HTTP Response Header to customize parameters and values for response headers.

Allow, Content-Encoding, and Content-Length

Note
  • An origin request is an HTTP message that is forwarded by DCDN to the origin for a specific accelerated domain name.

  • HTTP response header settings apply to any response message for your domain name. This configuration affects only HTTP messages returned to the origin through DCDN. HTTP messages that directly returned to the user by the points of presence (POPs) will not be modified.

  • You cannot configure HTTP response headers for wildcard domain names.

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 left-side navigation tree of the domain name, click Origin Fetch.

  5. Click the Response Headers tab.

  6. On the Response Headers page, click Customize.

  7. Configure the parameters as prompted.

    You can add HTTP headers to response URLs based on your business requirements. You can also replace, change, and delete the default HTTP header or HTTP headers that are added before or no longer needed from response URLs.

    Note

    If multiple operations are configured for the same origin response header, the operations are performed in the following sequence: Replace > Add > Change > Delete. For example, if you perform the Add operation and the Delete operation on the same request header at the same time, the request header is added and then deleted.

    • Parameters of the Add operation

      HTTP响应头

      Parameter

      Example

      Description

      Operation

      Add

      Adds a response header to response messages from an origin server.

      Response Header

      Custom Cache Response Headers

      You can select a preset response header, or select Custom Cache Response Headers from the Response Header drop-down list to specify a custom response header.

      Header Name

      x-code

      The name of the custom response header is x-code.

      Header Value

      key1

      You can specify one or more values for a response header. Separate multiple values with commas (,).

      key1,key2

      Allow Duplicates

      Yes

      If Allow Duplicates is set to Yes, you can set multiple values for the same parameter in the response header. Example: x-code:key1 and x-code:key2.

      No

      If Allow Duplicates is set to No, you can set only one value for one parameter in the response header. If you attempt to set multiple values for one parameter, the last added value takes effect. For example, if you add x-code:key1 and then add x-code:key2, only x-code:key2 takes effect.

    • Parameters of the Replace operation

      替换

      Parameter

      Example

      Description

      Operation

      Replace

      You can perform the Replace operation only if no duplicate response headers exist.

      Response Header

      Custom Cache Response Headers

      You can select a preset response header, or select Custom Cache Response Headers from the Response Header drop-down list to specify a custom response header.

      Header Name

      x-code

      The name of the custom response header is x-code.

      Find

      key

      You can search for the value that you want to replace by using regular expressions.

      Replace With

      abc

      You can replace matching values by using regular expressions.

      Match

      Match All

      If Match is set to Match All, all matching values are replaced. For example, if you use a regular expression to replace all strings of "key" in x-code:key1,key2,key3 with "abc", the key-value pair is changed to x-code:key1,key2,key3.

      Match the First Only

      If Match is set to Match the First Only, only the first matched value is replaced. For example, if you use a regular expression to replace the first "key" value in x-code:key1,key2,key3 with "abc", the key-value pair is changed to x-code:abc1,key2,key3.

    • Parameters of the Change operation

      变更

      Parameter

      Example

      Description

      Operation

      Change

      You can perform the Change operation only if no duplicate response headers exist.

      Response Header

      Custom Cache Response Headers

      You can select a preset response header, or select Custom Cache Response Headers from the Response Header drop-down list to specify a custom response header.

      Header Name

      x-code

      The name of the custom response header is x-code.

      Change To

      key1,key3

      You can specify one or more values for a response header. Separate multiple values with commas (,).

    • Parameters of the Delete operation

      删除

      Parameter

      Example

      Description

      Operation

      Delete

      Deletes all response headers that match the values of the Response Header and Header Name parameters. Duplicate response headers are also deleted.

      Response Header

      Custom Cache Response Headers

      You can select a preset response header, or select Custom Cache Response Headers from the Response Header drop-down list to specify a custom response header.

      Header Name

      x-code

      The name of the custom response header is x-code.

  8. Click OK.