When the cache on a CDN/ point of presence (POP) expires or a cache miss occurs, the CDN/ POP requests the latest content from the origin server. The content and HTTP headers returned by the origin server are called origin response headers. You can modify these headers on your origin server to define a cache policy, configure Cross-Origin Resource Sharing (CORS), and more. This allows you to optimize website loading speed, enhance content security, control resource accessibility, and improve the user experience.
Background
HTTP response headers are components of an HTTP response that carry specific parameters to the client.
When content requested by an end user is not cached on a CDN node, the CDN performs an origin fetch, and the origin server sends a response. You can modify the HTTP headers in this inbound response. For example, you can rewrite the value of the Content-Type header before it is passed to the client to ensure proper parsing. If the origin server returns an incorrect Content-Type value, the client may fail to parse the content correctly. You can resolve this issue by rewriting the header on the CDN.
-
An inbound response is the HTTP message that an origin server sends to a CDN node. Modifying inbound response headers only affects the HTTP message sent from the origin server to the CDN node; it does not affect responses the CDN node serves to the end user.
-
You cannot modify inbound response headers for wildcard domains.
Procedure
-
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names.
-
Find the domain name you want to manage and click Configure in the Actions column.
-
In the left navigation pane for the domain name, click Back-to-Origin.
-
Click the Origin HTTP Response Headers tab.
-
Click Add and configure the back-to-origin HTTP response header.
ImportantIf multiple operations apply to the same origin response header parameter, the operations are executed based on the following priority: Replace > Add > Change and Delete. For example, if both an add and a delete operation are configured for the same parameter, the add operation is executed before the delete operation.
Add response header
Delete response header
Modify response header
Replace response header
-
Click OK to complete the configuration.
Configuration examples
Example 1: Set a response MIME type
Use case
Set a specific MIME type for a response.
MIME types include the following main categories:
-
Text: Includes text files (such as .txt and .csv) and HTML files (such as .html, .htm, and .shtml).
-
Image: Includes common image files (such as .jpg, .png, and .gif).
-
Audio: Includes audio files (such as .mp3 and .wav).
-
Video: Includes video files (such as .mp4 and .avi).
-
Application: Includes application files (such as .pdf, .doc, and .xls).
Configuration
-
Response header operation: Add
-
Header name: Content-Type
-
Header value: text/html
Set Allow Duplicates to Do not allow and Rule Condition to Do not use, then click OK.
Result: The POP adds the Content-Type: text/html header to the response from the origin server. If you configure this header again, the new value overwrites the existing one.
Example 2: Delete a response header
Use case
Deleting a response header.
Configuration
-
Response header operation: Delete
-
Header name: Content-Type
Set Allow Duplicates to Do not allow and Rule Condition to Do not use, then click OK.
Result: The POP removes the Content-Type header from the response before returning it to the client.
If you apply the configurations from both Example 1 and Example 2, the system first adds and then deletes the Content-Type: text/html response header. As a result, the client receives the response without a specified MIME type.