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