All Products
Search
Document Center

ApsaraVideo VOD:Configure HTTP response headers

Last Updated:Aug 21, 2023

Alibaba Cloud CDN allows you to rewrite HTTP headers in HTTP response messages returned from an origin server. You can add, delete, change, and replace HTTP response headers based on your business requirements.

Background information

HTTP response headers are a component of the header section in response messages transmitted over HTTP. HTTP response headers bring specific parameters to clients.

If the requested resource is not cached on CDN nodes, the request is redirected to the origin server. Then, the origin server returns the requested resource to the CDN node. Alibaba Cloud CDN allows you to rewrite HTTP response headers from origin servers so that clients can identify response information more easily. For example, you can rewrite the value of the Content-Type header before it is returned to clients to ensure that the clients can parse the content retrieved from the origin server. If Content-Type is set to an invalid value, garbled text appears. In this case, the value of Content-Type must be rewritten on CDN nodes.

Responses to back-to-origin requests
Note
  • After an origin server receives a request from a CDN edge node, the origin server returns an HTTP message to the CDN edge node. A rewrite rule rewrites only HTTP headers in responses that are returned from an origin server. It does not rewrite HTTP headers in responses that are returned from CDN edge nodes to clients.
  • You cannot configure custom HTTP response headers for wildcard domain names.

Procedure

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names. The Domain Names page appears.

  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 pane of the specified domain name, click Back-to-Origin.

  5. Click the Origin HTTP Response Headers tab.

  6. Click Add and configure the parameters.

    Important If different operations are performed on the same response header at the same time, these operations have different priorities. The operations are prioritized in the following descending order: Replace > Add > Change or Delete. For example, if you perform the Add and Delete operations on the same request header at the same time, the request header is added and then deleted.
    • Parameters of the Add operationHTTP response header
      ParameterExampleDescription
      OperationAddAdds a response header to response messages from an origin server.
      Response HeaderCustom Cache Response Headers

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

      Header Namex-code

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

      Header Valuekey1

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

      key1,key2
      Allow DuplicatesAllow Duplicates
      • Yes: You can add duplicate response headers. For example, x-code:key1 and x-code:key2 can coexist.
      • No: The latest header value overwrites the existing one that uses the same header name. For example, if you add x-code:key1 and then add x-code:key2, the final header key-value pair is x-code:key2.
    • Delete operationParameters of the Delete operation
      ParameterExampleDescription
      OperationDeleteDeletes all response headers that match the values of the Response Header and Header Name parameters. Duplicate response headers are also deleted.
      Response HeaderCustom Cache Response Headers

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

      Header Namex-code

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

    • Parameters of the Change operationChange operation
      ParameterExampleDescription
      OperationChangeYou can perform the Change operation only if no duplicate response headers exist.
      Response HeaderCustom Cache Response Headers

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

      Header Namex-code

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

      Change Value Tokey1,key3

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

    • Parameters of the Replace operationReplace operation
      ParameterExampleDescription
      OperationReplaceYou can perform the Replace operation only if no duplicate response headers exist.
      Response HeaderCustom Cache Response Headers

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

      Header Namex-code

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

      FindkeyAllows you to use regular expressions to search for the value that you want to replace.
      Replace WithabcAllows you to use regular expressions to replace matching values.
      MatchMatch All
      • Match All: All matching values are replaced. For example, if you use a regular expression to replace all the "key" in x-code:key1,key2,key3 with "abc", the key-value pair is changed tox-code:abc1,abc2,abc3.
      • Match the First Only: Only the first matching value is replaced. For example, if you use a regular expression to replace the first "key" in x-code:key1,key2,key3 with "abc", the key-value pair is changed to x-code:abc1,key2,key3.
  7. Click OK.

Configuration examples

Example 1

Sample scenario: Adds a response header to specify that the content returned to users is of a specified MIME type.

Configuration: The following figure shows the configuration. Configuration

Expected result: The origin server adds the Content-Type header whose value is text/html to the response returned to CDN edge nodes. If the configuration is updated, the value is overwritten.

Example 2

Sample scenario:Deletes a response header from responses.

Configuration : The following figure shows the configuration. Configuration
Expected result: The Content-Type header is deleted from the response before it is returned to the user.
Note If the Add operation in Configuration Example 1 and the Delete operation in Configuration Example 2 are both performed, the Content-Type header with the value text/html is added to the response and then deleted. As a result, the content returned to the user is in the original type instead of a specified MIME type.

References

BatchSetVodDomainConfigs