回源配置
更新时间:2023-05-16
下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient
设置回源地址
case1:自定义回源回源端口,源站级host
                Python
                
            
            1def test_set_domain_origin(c):
2    """
3    test_set_domain_origin
4    """
5    origin = [
6                {'peer': '1.2.3.4', 'host': 'www.originhost.com'},
7                {'peer': '1.2.3.5', 'host': 'www.originhost.com'},
8                {'peer': 'http://1.2.3.8:80', 'host': 'www.originhost.com'}, # set origin with http port
9                {'peer': 'https://1.2.3.7:443', 'host': 'www.originhost.com'}, # set origin with https port
10                {'peer': '1.2.3.9:8080', 'host': 'www.originhost.com'} # set origin with http port
11             ]
12    response = c.set_domain_origin('example.test.com', origin)
13    print(response)
            case2:设置302跟随回源(follow302)
                Python
                
            
            1def test_set_domain_origin_with_follow302(c):
2    """
3    test_set_domain_origin_with_follow302
4    """
5    origin = [
6        {'peer': '1.2.3.4', 'host': 'www.originhost.com'}
7    ]
8    other = {
9        'follow302': True
10    }
11    
12    response = c.set_domain_origin('example.test.com', origin, other)
13    print(response)
            case3:设置域名级默认回源host(defaultHost)
                Python
                
            
            1def test_set_domain_origin_with_defaulthost(c):
2    """
3    test_set_domain_origin_with_defaulthost
4    """
5    origin = [
6        {'peer': '1.2.3.4', 'host': 'www.originhost.com'}
7    ]
8    other = {
9        'defaultHost': 'myhost.com'
10    }
11    
12    response = c.set_domain_origin('example.test.com', origin, other)
13    print(response)
            设置 Range 回源
                Python
                
            
            1def test_set_domain_range_switch(c):
2    """
3    test set domain range switch
4    """
5    range_switch = True
6    domain = 'test-sdk.sys-qa.com'
7    response = c.set_domain_range_switch(domain, range_switch);
8    print(response)
            查询 Range 回源
                Python
                
            
            1def test_get_domain_range_switch(c):
2    """
3    test get domain range switch
4    """
5    response = c.get_domain_range_switch('test-sdk.sys-qa.com')
6    print(response)
            设置移动访问控制
                Python
                
            
            1def test_set_domain_mobile_access(c):
2    """
3    test set domain mobile access 
4    """
5    mobile_access = {
6        "distinguishClient": True
7    }
8    domain = 'test-sdk.sys-qa.com'
9    response = c.set_domain_mobile_access(domain, mobile_access);
10    print(response)
            查询移动访问控制
                Python
                
            
            1def test_get_domain_mobile_access(c):
2    """
3    test get domain mobile access
4    """
5    response = c.get_domain_mobile_access('test-sdk.sys-qa.com')
6    print(response)
            设置回源协议
                Python
                
            
            1def test_set_origin_protocol(c):
2    """
3    test_set_origin_protocol
4    """
5    origin_protocol = {
6        "value": "http"
7    }
8    response = c.set_domain_origin_protocol('example.test.com', origin_protocol)
9    print(response)
            查询回源协议
                Python
                
            
            1def test_get_origin_protocol(c):
2    """
3    test_get_origin_protocol
4    """
5    response = c.get_domain_origin_protocol('example.test.com')
6    print(response)
            设置回源错误重试
case1:开启回源错误重试,设置错误码为500,502时重试
                Python
                
            
            1def test_set_retry_origin(c):
2    """
3    test_set_retry_origin
4    """
5    retry_origin = {
6        "codes": [
7            500,
8            502
9        ]
10    }
11    response = c.set_domain_retry_origin('example.test.com', retry_origin)
12    print(response)
            case2:关闭回源错误重试
                Python
                
            
            1def test_set_retry_origin_off(c):
2    """
3    test_set_retry_origin_off
4    """
5    retry_origin = {
6        "codes": []
7    }
8    response = c.set_domain_retry_origin('example.test.com', retry_origin)
9    print(response)
            查询回源错误重试配置
                Python
                
            
            1def test_get_retry_origin(c):
2    """
3    test_get_retry_origin
4    """
5    response = c.get_domain_retry_origin('example.test.com')
6    print(response)
            