All Products
Search
Document Center

:Configure HTTP request headers (new)

Last Updated:Aug 14, 2024

By default, Dynamic Content Delivery Network (DCDN) supports request headers such as client IP addresses. You can also configure custom request headers. Dynamic Content Delivery Network (DCDN) allows you to rewrite HTTP headers in origin requests. You can add, delete, change, or replace HTTP headers in origin requests based on your business requirements.

Prerequisites

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

Background information

HTTP request headers are a component of the header section in requests that are transmitted over HTTP. HTTP request headers include specific parameters that are sent to servers.

When points of presence (POPs) retrieve the requested resources from an origin server, the origin server can obtain information that is included in request headers. Dynamic Content Delivery Network (DCDN) allows you to rewrite HTTP headers in origin requests. The information that is included in request headers is passed to the origin server to meet specific business requirements. For example, you can configure the X-Forwarded-For (XFF) header to pass client IP addresses to your origin server.

For information about how the origin server obtains the IP address of a client from the XFF header in the origin request, see Retrieve the originating IP addresses of clients.

image

Usage notes

  • An origin request is an HTTP message that is transmitted by DCDN to the origin server of a specific accelerated domain name. A rewrite rule rewrites only the HTTP headers in requests that are transmitted between an origin server and POPs. A rewrite rule does not rewrite the HTTP headers in requests that are transmitted between POPs and clients.

  • You cannot specify custom HTTP request headers for wildcard domain names.

  • By default, DCDN supports the following HTTP request headers, which do not need to be configured.

    Origin HTTP header

    Description

    Example

    Ali-Cdn-Real-Ip

    The IP address that is used by the client to connect to a POP.

    Ali-Cdn-Real-Ip:192.168.0.1

    X-Forwarded-For

    The IP address of the client and IP address of a POP that is used to connect to the origin server.

    X-Forwarded-For:192.168.0.1, 172.16.0.1

    X-Client-Scheme

    The protocol that is used by the client to send the request to a POP, such as HTTP or HTTPS.

    X-Client-Scheme:http

    Host

    The domain name of the origin server to which the request is redirected.

    Host:example.com

    Via

    The names of all POPs that the request passes through.

    Via:cn2546-10.l1, cache1.cn2546-10, l2cn2547-7.l2, cache1.l2cn2547-7

  • If the value of the HTTP request header is a variable, a specific value is assigned to the variable when the variable is used. The following table describes available variables.

    Parameter

    Origin HTTP header

    Description

    Example

    Ali-Cdn-Real-Port

    $http_Ali_Cdn_Real_Port

    Adds a header that passes the client port to the origin server.

    Ali-Cdn-Real-Port:80

    Ali_Cdn_Real_Ip

    $http_Ali_Cdn_Real_Ip

    Adds a header that passes the client IP address to the origin server.

    Ali-Cdn-Real-Ip:192.168.0.1

    x_forwarded_for

    $proxy_add_x_forwarded_for

    Adds the XFF header to origin requests. The XFF header passes the client IP address and proxy IP address to the origin server.

    X-Forwarded-For:192.168.0.1, 172.16.0.1

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 Custom Request Headers (New).

  6. On the Custom Request Headers (New) tab, click Add.

  7. Configure the parameters in the dialog box that appears.

    Important

    If different operations are performed on the same request header at the same time, the operations are assigned different priorities. The operations are prioritized in the following order: 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

    Parameter

    Example

    Description

    Operation

    Add

    Adds a request header to origin HTTP requests.

    Request Header

    Custom Header

    You can select a preset request header, or select Custom Header from the Request Header drop-down list to specify a request header.

    Request Header Name

    x-code

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

    Header Value

    key1

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

    key1, key2

    Allow Duplicates

    Yes

    • Yes: You can add duplicate request headers. Example: x-code:key1 and x-code:key2.

    • 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, only x-code:key2 takes effect.

    Parameters of the Delete operation

    Parameter

    Example

    Description

    Operation

    Delete

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

    Request Header

    Custom Header

    You can select a preset request header, or select Custom Header from the Request Header drop-down list to specify a request header.

    Request Header Name

    x-code

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

    Parameters of the Change operation

    Parameter

    Example

    Description

    Operation

    Change

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

    Request Header

    Custom Header

    You can select a preset request header, or select Custom Header from the Request Header drop-down list to specify a request header.

    Request Header Name

    x-code

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

    Change To

    key1, key3

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

    Parameters of the Replace operation

    Parameter

    Example

    Description

    Operation

    Replace

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

    Request Header

    Custom Header

    You can select a preset request header, or select Custom Header from the Request Header drop-down list to specify a request header.

    Request Header Name

    x-code

    The name of the custom request 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

    • 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: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" value in x-code:key1,key2,key3 with "abc", the key-value pair is changed to x-code:abc1,key2,key3.

  8. Click OK.

Related API operations

BatchSetDcdnDomainConfigs