HTTP Header Settings (Cross-origin Requests)
HTTP headers are part of an HTTP request or response message that define the operating parameters of an HTTP transaction.
Cross-origin resource sharing (CORS) is a mechanism that allows cross-origin access. When website A accesses resources on website B, a cross-origin request is sent. If website B does not allow website A to access the resources, a cross-domain problem occurs. In this case, you can configure HTTP header settings and add custom headers in response messages returned to the requester to implement functions such as CORS.
Precautions
- Some headers cannot be set or deleted. For details, see Constraints.
- You can add up to 10 HTTP response header configurations.
- HTTP header configuration is domain name-specific. When the configuration takes effect, the specified headers will be added to or removed from response messages for any resources under the entire domain. However, HTTP header configuration only affects the response behavior of the clients (browsers). They do not affect the cache behavior of CDN PoPs.
- If your domain name is an OBS bucket and CORS rules are configured on CDN, you also need to configure CORS on OBS.
Supported Response Headers
Huawei Cloud CDN lets you customize the following different HTTP response headers:
- Content-Disposition
The Content-Disposition header can start a download on the client side and specify the name of the file to be downloaded.
When a server sends a file to a browser, as long as the file format is supported (for instance TXT or JPG), the file is opened using the browser by default. If the file needs to be treated as an attachment and saved with a specific file name, you can use the Content-Disposition header field to specify this requirement.
If you use an OBS bucket created after January 1, 2022 as the origin server and want to enable online preview, set Content-Disposition to inline. For details, see How Do I Preview Objects in OBS Through a Browser?
- Content-Language
The Content-Language header specifies the preferred language or language combination of the browser. Content can be customized for different users.
- Access-Control-Allow-Origin
The Access-Control-Allow-Origin header carries the domain names that are allowed for CORS after server authentication. For a simple CORS request, the browser determines whether to return the requested resource content to the client based on this message header. For a pre-check request, the browser determines whether to initiate an actual CORS request to the server based on this message header.
To prevent cross-domain errors caused by browser cache, clear browser cache after configuring Access-Control-Allow-Origin.
- Access-Control-Allow-Methods
The Access-Control-Allow-Methods header carries the methods that are allowed for CORS after server authentication. For a simple CORS request, the browser determines whether to return the requested resource content to the client based on this message header. For a pre-check request, the browser determines whether to initiate an actual CORS request to the server based on this message header.
- Access-Control-Max-Age
The Access-Control-Max-Age header determines how long the pre-check results for CORS requests allowed by the server can be cached. The browser determines the TTL for pre-check request results based on this message header. As long as the period defined by this header has not expired, the browser can determine whether to initiate a CORS request to the server based on the results. Once this period expires, the browser needs to send another pre-check request to the server.
- Access-Control-Expose-Headers
Access-Control-Expose-Headers specify the response headers that the browser can expose to the client. You can use this field to define the response headers visible to the client. The following response headers are visible to the client by default: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, and Pragma.
- Custom
If the preceding response headers cannot meet your needs, you can create response headers. A custom response header can contain 1 to 100 characters, starting with a letter and consisting of letters, digits, and hyphens (-).
Procedure
- Log in to the CDN console.
- In the navigation pane, choose .
- In the domain list, click the target domain name or click Configure in the Operation column.
- Click the Advanced Settings tab.
- In the HTTP Headers area, click Edit. The Configure HTTP Headers dialog box is displayed.
Figure 1 Configuring HTTP headers
- Click Add and select a response header operation from the drop-down list.
Response Header Operation
Description
Set
- If the header already exists in the response, the header value you configure will overwrite the original one.
- If the header does not exist in the response, the header will be added to the response.
Delete
The header will be deleted from the response.
- Set the header parameter and value.
Parameter
Description
Example Value
Content-disposition
Starts a download on the client side and specifies the name of the file to be downloaded.
Value requirements: For a typical configuration, see the example on the right.
attachment;filename=FileName.xls
Content-Language
Specifies the language of the response page of the client.
Value requirements: For a typical configuration, see the example on the right.
zh-CN
en-US
Access-Control-Allow-Origin
Specifies the foreign domain URLs (request sources) that are allowed to access the resource in cross-origin resource sharing (CORS).
Value requirements:
- Enter a URL or up to 66 URLs.
- Wildcard domain names are supported.
- Enter up to 1,000 characters.
- Separate URLs with commas (,).
- Start with http:// or https://.
- If this is set to *, no URLs are allowed after the wildcard (*).
- Domain names with port numbers are supported.
- The value can be null, which is case-insensitive.
Example 1:
https://www.example.com
Example 2:
*
Example 3:
https://www.example.com,https://www.example01.com,https://*.abc.com
Access-Control-Allow-Methods
Specifies the HTTP request methods that can be used in a CORS request.
Value requirements: Multiple methods can be configured at the same time. Separate them with commas (,).
GET,POST,HEAD
Access-Control-Max-Age
Specifies how long to cache the pre-check results of CORS requests on specific resources.
Value requirements: This value is expressed in seconds and ranges from 0 to 1,000,000,000.
86400
Access-Control-Expose-Headers
Specifies the response header information visible to the client for a CORS request.
Value requirements: Enter 1 to 256 characters. Multiple headers can be configured at the same time. Separate them by commas (,).
Content-Length,Content-Encoding
Access-control-allow-headers
Specifies the fields that can be carried in a cross-domain request.
Value requirements: Enter 1 to 1,000 characters. Multiple fields can be configured at the same time. Separate them by commas (,).
X- Custom-Header
Custom
Specifies the custom response header for a CORS request.
Value requirements: Enter 1 to 1,000 characters, which can contain letters, digits, spaces, and the following special characters: .-_*#!&+|^~'"/:;,=@?<>
NOTE:- If the custom parameter is Cache-Control, the value can be max-age=*** (*** is a number), private, no-cache, no-store, or public. Only one value can be configured.
x-testcdn
- Click OK.
Constraints
- If your domain name has special configurations, Content-Type, Expires, or Cache-Control cannot be configured.
- The following response headers can be modified but cannot be deleted.
Content-Base
Content-Disposition
Server
Content-Language
Cache-Control
Expires
Content-Type
-
- CDN does not support the following response headers:
A_Dynamic
If-None-Match
Sec-WebSocket-Origin
X-Forward-Peer
Accept-Ranges
If-Range
Sec-WebSocket-Protocol
X-Forward-Type
X-Forward-Ip
Keep-Alive
Sec-WebSocket-Version
X-Forward-Uri
Allow
Key
Set-Cookie
X-Forwarded-For
Authentication-Info
Last-Modified
Tcp-Retrans
X-IP-Region
Authorization
Link
Title
X-IP-Region-CN
X-Forward-Measured
Location
Transfer-Encoding
X-Ip-Blackwhite-List
Cdn-Qos
Max-Forwards
Upgrade
X-Local-Ip
Cdn-Server-Ip
Meter
Vary
X-Log-Url
Cdn-Src-Ip
Mime-Version
Via
X-MAA-Alias
Conf-Err-Host
Negotiate
WWW-Authenticate
X-MAA-Auth
Conf-File
Origin
Warning
X-Max-Conns
Conf-File-List
Partition-Block-Size
Ws-Hdr
X-Mem-Url
Conf-Option
Pragma
WsTag
X-Mgr-Traffic
Conf-Other
Proxy-Authenticate
X-Accelerator-Vary
X-Miss-Rate-Limit
Connection
Proxy-Authentication-Info
X-Appa
X-Miss-Times-Limit
Content-Encoding
Proxy-Authorization
X-Appa-Origin
X-No-Referer
Content-Length
Proxy-Connection
X-Black-List
X-Query-Key
Content-Location
Proxy-Support
X-Bwctrl-Limit
X-Rate-Limit
Content-MD5
Public
X-Bwctrl-Para
X-Refresh-Pattern
Content-Range
Purge-Domain
X-Cache
X-Request-Id
Sec-WebSocket-Nonce
Purge-Extra
X-Cache-2
X-Request-Uri
Date
Range
X-Cache-Lookup
X-Request-Url
Dynamic
Request-Range
X-Cacheable
X-Resp-Time
ETag
Retry-After
X-Cdn-Src-Port
X-Rewrite-Url
Error
Sec-WebSocket-Accept
X-Client-Ip
X-Squid-Error
Expect
Sec-WebSocket-Draft
X-DNS-Time
X-Times-Limit
If-Modified-Since
Sec-WebSocket-Extensions
X-Denyattack-Dynconf
X-Url-Blackwhite-List
From
Sec-WebSocket-Key
X-Error-Status
X-Via-CDN
Front-End-Https
Sec-WebSocket-Key1
X-Error-URL
X-White-List
Host
Sec-WebSocket-Key2
X-Forward-Host
-
If-Match
Sec-WebSocket-Location
-
-
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot