Updated on 2025-08-22 GMT+08:00

Modifying a Domain Name Template

Function

This API is used to modify a domain name template.

Calling Method

For details, see Calling APIs.

URI

PUT /v1.0/cdn/configuration/templates/{tml_id}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

tml_id

Yes

String

Definition

Domain name template ID, which can be obtained by calling the API for listing domain name templates.

Constraints

N/A

Range

N/A

Default Value

N/A

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

tml_name

Yes

String

Definition

Domain name template name.

Constraints

N/A

Range

  • Enter 1 to 100 characters.

  • Use only letters, digits, underscores (_), and hyphens (-).

Default Value

N/A

remark

No

String

Definition

Domain name template description.

Constraints

N/A

Range

N/A

Default Value

N/A

configs

Yes

TemplateConfigs object

Definition

Domain name template configuration.

Constraints

N/A

Table 3 TemplateConfigs

Parameter

Mandatory

Type

Description

http_response_header

No

Array of HttpResponseHeader objects

HTTP response header settings

cache_rules

No

Array of CacheRules objects

origin_follow302_status

No

String

Definition

Whether to enable redirect from origin. If the origin server uses 301/302 redirection, CDN PoPs redirect to the address specified in a 301/302 response, cache the resource, and return it to the user.

Constraints

N/A

Range

  • on: enabled.

  • off: disabled.

Default Value

N/A

compress

No

Compress object

Definition

Smart compression. CDN can compress static content on websites by reducing file size. This speeds up file transfer and saves a lot of bandwidth.

Constraints

N/A

origin_range_status

No

String

Definition

Range requests for origin pull. A range request allows the origin server to send data of a specific range to a CDN PoP based on the range information in the HTTP request header.

Constraints

To enable range requests for origin pull, the origin server must support range requests, that is, requests with the Range field in the headers. Otherwise, origin pull may fail.

Range

  • on: enabled.

  • off: disabled.

Default Value

N/A

ip_filter

No

IpFilter object

Definition

IP access control list (ACL), which blocks or allows access from specific IP addresses.

Constraints

N/A

referer

No

RefererConfig object

Definition

Referrer whitelist or whitelist, which identifies and filters user identities to control access.

Constraints

N/A

user_agent_filter

No

UserAgentFilter object

Definition

User-Agent ACL, which filters out requests from specific proxies.

Constraints

N/A

flow_limit_strategy

No

Array of FlowLimitStrategy objects

Definition

Usage cap. When the actual data exceeds the cap you set, CDN blocks the domain name to prevent excess billing caused by traffic theft or attacks.

NOTE:
Blocking may be delayed by about 10 minutes after the monitored data reaches the cap.

Constraints

N/A

Table 4 HttpResponseHeader

Parameter

Mandatory

Type

Description

name

Yes

String

Definition

Name of an HTTP response header.

Constraints

N/A

Range

  • Enter 1 to 100 characters.

  • Use only letters, digits, and hyphens (-). Start with a letter.

Default Value

N/A

value

No

String

Definition

Value of the HTTP response header.

Constraints

N/A

Range

  • Enter 1 to 1,000 characters.

  • Use only letters, digits, and the following special characters: .-_*#!&+|^~'"/:;,=@?<>

  • This parameter is optional when the header is to be deleted.

Default Value

N/A

action

Yes

String

Definition

Operation type of the HTTP response header.

Constraints

  • A response header field can only be deleted or set.

  • When action is set to set, if the header does not exist in the original HTTP response, it is added. If it exists, it is modified.

Range

  • set

  • delete

Default Value

N/A

Table 5 CacheRules

Parameter

Mandatory

Type

Description

match_type

Yes

String

Definition

Match type.

Constraints

N/A

Range

  • all: all files.

  • file_extension: file name extension.

  • catalog: directory.

  • full_path: full path.

  • home_page: homepage.

Default Value

N/A

match_value

No

String

Definition

Cache rule match content.

Constraints

  • When match_type is set to all, this parameter is left blank.

  • When match_type is set to file_extension, the value of this parameter is a list of up to 100 file types with up to 1,000 characters. A file type starts with a period (.). File types are separated by commas (,) or semicolons (;). Example: .jpg,.zip,.exe.

  • When match_type is set to catalog, the value of this parameter is a list of up to 20 directories with up to 255 characters. A directory starts with a slash (/). Directories are separated by commas (,) or semicolons (;). Example: /test/folder01,/test/folder02.

  • When match_type is set to full_path, the value of this parameter is a full path. A full path starts with a slash (/) and supports wildcard characters (*). A cache rule can contain only one full path, for example, /test/index.html or /test/*.jpg. /* is not allowed.

  • When match_type is set to home_page, this parameter is left blank.

Range

N/A

Default Value

N/A

ttl

No

Integer

Definition

TTL of a resource cached on CDN PoPs.

Constraints

Up to 365 days.

Range

N/A

Default Value

0

ttl_unit

Yes

String

Definition

Unit of the cache TTL.

Constraints

N/A

Range

  • s: second.

  • m: minute.

  • h: hour.

  • d: day.

Default Value

N/A

priority

Yes

Integer

Definition

Cache rule priority. A larger value indicates a higher priority.

Constraints

The priority of a rule must be unique.

Range

1 to 100.

Default Value

N/A

follow_origin

No

String

Definition

Source of the cache TTL, that is, whether CDN PoPs use the cache TTL set on the origin server or that set in cache rules on CDN.

Constraints

N/A

Range

  • on: CDN PoPs use the TTL set on the origin server.

  • off: CDN PoPs use the TTL set in cache rules.

  • min_ttl: CDN PoPs use the shorter TTL between the TTL set on the origin server and that in cache rules.

Default Value

off

force_cache

No

String

Definition

Forcible cache. Specify whether CDN PoP cache ignores the no-cache, private, and no-store fields in the Cache-Control response header sent from the origin server.

Constraints

Forcible cache is used together with cache TTL source. For details about the restrictions and configuration effect, see section "PoP Cache Rules" in the User Guide of CDN.

Range

  • on: enabled.

  • off: disabled.

Default Value

off

url_parameter_type

No

String

Definition

URL parameter filtering.

Constraints

N/A

Range

  • del_params: Ignore specific URL parameters.

  • reserve_params: Retain specific URL parameters.

  • ignore_url_params: Ignore all URL parameters.

  • full_url: Retain all URL parameters.

Default Value

full_url

url_parameter_value

No

String

Definition

URL parameters.

Constraints

  • Enter up to 30 parameters.

  • Separate parameters by commas (,) or semicolons (;).

  • This parameter is mandatory when url_parameter_type is set to del_params or reserve_params.

Range

N/A

Default Value

N/A

Table 6 Compress

Parameter

Mandatory

Type

Description

status

Yes

String

Definition

Smart compression status.

Constraints

N/A

Range

  • on: enabled.

  • off: disabled.

Default Value

N/A

type

No

String

Definition

Smart compression type.

Constraints

If multiple smart compression types are configured, Brotli compression is used first.

Range

Separate smart compression types by commas (,).

  • gzip: gzip compression.

  • br: Brotli compression.

Default Value

N/A

file_type

No

String

Definition

Types of files to compress.

Constraints

N/A

Range

  • Enter up to 2,000 characters.

  • Enter up to 50 characters for each type.

  • Separate types by commas (,).

Default Value

The default value is .js,.html,.css,.xml,.json,.shtml,.htm when smart compression is used for the first time. When this function is used again and this value is left empty, the result of the previous setting is used.

compress_min_length

No

Integer

Definition

Minimum size of files to be compressed.

Constraints

CDN compresses files between 0 MB and 30 MB if no specific file size is set.

Range

  • 0 MB to 30 MB. The unit is byte.

Default Value

N/A

compress_max_length

No

Integer

Definition

Maximum size of files to be compressed.

Constraints

CDN compresses files between 0 MB and 30 MB if no specific file size is set.

Range

  • 0 MB to 30 MB. The unit is byte.

Default Value

N/A

Table 7 IpFilter

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

IP ACL type.

Constraints

N/A

Range

  • off: The IP ACL is disabled.

  • black: IP address blacklist.

  • white: IP address whitelist.

Default Value

N/A

value

No

String

Definition

IP ACL.

NOTE:
IPv6 is supported. IP addresses and CIDR blocks in the IP address/Subnet mask format are supported.

Constraints

  • This parameter is optional when type is set to off.

  • Separate rules by commas (,).

  • Enter up to 500 rules.

  • Duplicate IP addresses and CIDR blocks will be removed.

  • Wildcards are not supported, for example, 192.168.0.*.

Range

N/A

Default Value

N/A

Table 8 RefererConfig

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

Type of the referer blacklist or whitelist.

Constraints

N/A

Range

  • off: The referer blacklist/whitelist is disabled.

  • black: referer blacklist.

  • white: referer whitelist.

Default Value

N/A

value

No

String

Definition

Domain names or IP addresses.

NOTE:
Domain name and IP address can be entered together. Wildcard domain names and domain names with port numbers are supported.

Constraints

  • Separate domain names and IP addresses by commas (,).

  • Enter up to 1,000 domain names and IP addresses.

  • A port ranges from 1 to 65535.

Range

N/A

Default Value

N/A

include_empty

No

Boolean

Definition

Whether blank referers are included.

NOTE:
A referer blacklist including blank referers indicates that requests without any referers are not allowed to access.

A referer whitelist including blank referers indicates that requests without any referers are allowed to access.

Constraints

N/A

Range

  • true: Blank referers are included.

  • false: Blank referers are not included.

Default Value

false

Table 9 UserAgentFilter

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

User-Agent ACL type.

Constraints

N/A

Range

  • off: The User-Agent ACL is disabled.

  • black: User-Agent blacklist.

  • white: User-Agent whitelist.

Default Value

N/A

value

No

String

Definition

User-Agent ACL content.

NOTE:
This old parameter will be deprecated recently. Use ua_list to set a User-Agent ACL.

Constraints

  • This parameter is optional when type is set to off.

  • Configure up to 50 rules.

  • Separate rules by commas (,).

Range

  • Enter up to 200 characters for each rule.

  • Use only letters, digits, spaces, and the following special characters: *.-_();,/'#!@$^&+=~?"[]{}:%

Default Value

N/A

include_empty

No

Boolean

Definition

Whether blank user agents are included.

NOTE:
A blacklist including blank user agents indicates that requests without any user agents are not allowed to access.

A whitelist including blank user agents indicates that requests without any user agents are allowed to access.

Constraints

N/A

Range

true: Blank user agents are included.

false: Blank user agents are not included.

Default Value

  • false for blacklists.

  • true for whitelists.

ua_list

No

Array of strings

Definition

User-Agent ACL.

Constraints

  • This parameter is optional when type is set to off.

  • Configure up to 50 rules.

  • Enter up to 200 characters for each rule.

  • When ua_list and value are both set, ua_list is used.

Table 10 FlowLimitStrategy

Parameter

Mandatory

Type

Description

strategy_type

No

String

Definition

Measurement type.

Constraints

N/A

Range

  • instant: instantaneous usage.

  • hour: hourly cumulative usage.

  • day: daily cumulative usage.

Default Value

N/A

item_type

No

String

Definition

Usage cap type.

Constraints

N/A

Range

  • bandwidth: bandwidth cap, in bit/s.

  • traffic: traffic cap, in bits.

Default Value

N/A

limit_value

No

String

Definition

Usage cap. When the usage of a domain name reaches this cap, CDN will be disabled for it.

Constraints

N/A

Range

The value must be a positive integer.

Default Value

N/A

alarm_percent_threshold

No

String

Definition

Usage alarm threshold. When the domain name usage reaches this threshold, an alarm is sent.

Constraints

N/A

Range

1 to 90.

Default Value

N/A

ban_time

No

String

Definition

Capping period.

Constraints

Setting ban_time to 0 indicates that the domain name is not automatically unblocked. You need to manually unblock it.

Range

  • 0: Block the domain name until you manually unblock it.

  • 60: 60 minutes (1 hour).

  • 720: 720 minutes (12 hours).

  • 1440: 1,440 minutes (24 hours).

  • 4320: 4,320 minutes (3 days).

Default Value

N/A

Response Parameters

Status code: 204

Success response

Status code: default

Table 11 Response body parameters

Parameter

Type

Description

error

ErrMsg object

Error code and error message.

Table 12 ErrMsg

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

PUT https://cdn.myhuaweicloud.com/v1.0/cdn/configuration/templates/example********************tmlid

{
  "tml_name" : "example",
  "remark" : "example remark",
  "configs" : {
    "http_response_header" : [ {
      "action" : "set",
      "name" : "Content-Disposition",
      "value" : "example"
    } ]
  }
}

Example Responses

None

SDK Sample Code

The SDK sample code is as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cdn.v2.region.CdnRegion;
import com.huaweicloud.sdk.cdn.v2.*;
import com.huaweicloud.sdk.cdn.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateDomainTemplateSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CdnClient client = CdnClient.newBuilder()
                .withCredential(auth)
                .withRegion(CdnRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDomainTemplateRequest request = new UpdateDomainTemplateRequest();
        request.withTmlId("{tml_id}");
        CreateTemplateRequestBody body = new CreateTemplateRequestBody();
        [](model.HttpResponseHeader) listConfigsHttpResponseHeader = new ArrayList<>();
        listConfigsHttpResponseHeader.add(
            new HttpResponseHeader()
                .withName("Content-Disposition")
                .withValue("example")
                .withAction("set")
        );
        TemplateConfigs configsbody = new TemplateConfigs();
        configsbody.withHttpResponseHeader(listConfigsHttpResponseHeader);
        body.withConfigs(configsbody);
        body.withRemark("example remark");
        body.withTmlName("example");
        request.withBody(body);
        try {
            UpdateDomainTemplateResponse response = client.updateDomainTemplate(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = CdnClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CdnRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateDomainTemplateRequest()
        request.tml_id = "{tml_id}"
        listHttpResponseHeaderConfigs = [
            HttpResponseHeader(
                name="Content-Disposition",
                value="example",
                action="set"
            )
        ]
        configsbody = TemplateConfigs(
            http_response_header=listHttpResponseHeaderConfigs
        )
        request.body = CreateTemplateRequestBody(
            configs=configsbody,
            remark="example remark",
            tml_name="example"
        )
        response = client.update_domain_template(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cdn.NewCdnClient(
        cdn.CdnClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDomainTemplateRequest{}
	request.TmlId = "{tml_id}"
	valueHttpResponseHeader:= "example"
	var listHttpResponseHeaderConfigs = []model.HttpResponseHeader{
        {
            Name: "Content-Disposition",
            Value: &valueHttpResponseHeader,
            Action: "set",
        },
    }
	configsbody := &model.TemplateConfigs{
		HttpResponseHeader: &listHttpResponseHeaderConfigs,
	}
	remarkCreateTemplateRequestBody:= "example remark"
	request.Body = &model.CreateTemplateRequestBody{
		Configs: configsbody,
		Remark: &remarkCreateTemplateRequestBody,
		TmlName: "example",
	}
	response, err := client.UpdateDomainTemplate(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

204

Success response

default

Abnormal response

Error Codes

See Error Codes.