Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

HTTP Header Settings (Cross-origin Requests)

Updated on 2024-12-27 GMT+08:00

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 rules.
  • 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 a CORS rule is configured on the CDN console, synchronize it to your origin server. If your origin server is the domain name of an OBS bucket, configure CORS on OBS.

Supported Response Headers

Huawei Cloud CDN lets you customize the following different HTTP response headers:

  • Content-Disposition

    This header can start a download on clients 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 example, TXT or JPG), the file is opened using the browser by default. You can use this header to treat the file as an attachment and let users save it with a specific file name.

    NOTE:

    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 OBS Objects in My Web Browser?

  • Content-Language

    This header specifies the preferred language or language combination of the browser. Content can be customized for different users.

  • Access-Control-Allow-Origin

    This 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 content to the client based on this header. For a preflight request, the browser determines whether to initiate an actual CORS request to the server based on this header.

    NOTE:

    To prevent cross-domain errors caused by browser cache, clear browser cache after configuring Access-Control-Allow-Origin.

  • Access-Control-Allow-Methods

    This 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 content to the client based on this header. For a preflight request, the browser determines whether to initiate an actual CORS request to the server based on this header.

  • Access-Control-Max-Age

    This header determines how long the results of CORS preflight requests allowed by the server can be cached. The browser determines the TTL for preflight request results based on this header. As long as the TTL has not expired, the browser can determine whether to initiate a CORS request to the server. Once this TTL expires, the browser needs to send another preflight request to the server.

  • Access-Control-Expose-Headers

    This header specifies the response headers that the browser can expose to the client. You can use this header 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 contains 1 to 100 characters, starting with a letter and consisting of letters, digits, and hyphens (-).

Procedure

  1. Log in to the CDN console.
  2. In the navigation pane, choose Domains.
  3. In the domain list, click the target domain name or click Configure in the Operation column.
  4. Click the Advanced Settings tab.
  5. In the HTTP Headers area, click Edit. The Configure HTTP Headers dialog box is displayed.
    Figure 1 Configuring HTTP headers

  6. 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.

  7. 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: Enter 1 to 1,000 characters. 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: Enter 1 to 1,000 characters. 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 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: Enter 1 to 1,000 characters. Separate methods by commas (,).

    GET,POST,HEAD

    Access-Control-Max-Age

    Specifies how long to cache the results of CORS preflight 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 1,000 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. A response header starts with a letter and contains 1 to 100 characters, including letters, digits, and hyphens (-).

    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 public, private, no-cache, no-store, no-transform, only-if-cached, proxy-revalidate, must-revalidate, immutable, max-age=***, stale-while-revalidate=***, s-maxage=***, stale-if-error=***, or min-fresh=*** (*** is a number). Enter up to 10 values and separate them by commas (,).
    • The value of the Cache-Control header may affect the PoP cache.

    x-testcdn

  8. Click OK.

Constraints

  • If your domain name has special configurations, Content-Type, Expires, Vary, or Cache-Control cannot be configured.
  • The following response headers can only be modified. Response Header Operation cannot be set to Delete for them.

    Content-Base

    Content-Type

    Server

    Content-Language

    Cache-Control

    Expires

  • CDN does not support the following response headers.

    a_dynamic

    upgrade

    content-md5

    accept-ranges

    meter

    content-range

    keep-alive

    www-authenticate

    date

    allow

    proxy-authenticate

    range

    set-cookie

    connection

    etag

    authentication-info

    content-encoding

    retry-after

    last-modified

    proxy-authorization

    error

    location

    content-length

    if-modified-since

    transfer-encoding

    content-location

    host

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback