应用安全解决方案、区块链安全加速解决方案、IPv6安全加速解决方案、点播分发、直播分发、移动加速、网页加速、下载分发、全站加速、应用安全加速解决方案、IPv6一体化解决方案、电商安全加速解决方案、金融安全加速解决方案、政企安全加速解决方案
通过接口自助实现http头部增删改功能,可通过在cdn层对客户实现个性化http头部控制,让客户在不需要修改源站的情况下,实现定制化的http头部和加速效果的提升。接口url的*可为域名名称或域名id。
单用户调用频率:300/5min
Open API在线调试功能提供可视化界面在线调试API、支持生成代码示例、快速检索查看API文档等能力。前往调试
参数名称 | 描述 |
---|---|
*domain-nameString | 需要查询配置的域名或域名id |
参数名称 | 描述 |
---|---|
*header-modify-rulesList | http头设置
注意:
1. 需要取消http头设置时,可以传入空节点 |
data-idLong | 添加grid类型标识,表示客户多组配置时,具体某组配置。
data-id可以通过查询接口获取。
注意:添加grid类型标识:data-id,每一组配置对应一个data-id:
a、如果客户有传data-id,说明指定修改其中一组配置项内容,不需求修改其他组配置内容不需要入参;
b、如果客户入参多组配置,其中有些组配置有传data-id,有些没有传,则有传data-id的表示修改具体某组配置,没有传data-id的表示在原来基础上新增一组配置;
c、如果客户入参都没有传data-id,表示用本次的配置全量覆盖原先配置;
d、如果客户入参没有传任何配置项参数,只传了域名和二级标签,表示清空这个接口对应域名二级服务所有配置。(c、d内容和当前方案实现一致);
e、一个gird标签下的入参不能为空,如果,没有具体的配置项,则data-id必填,且值为实际存在的data-id,表示清空这个data-id对应配置项的值; |
path-patternString | url匹配模式,支持正则,如果是全部匹配,入参可以配置为:.* |
except-path-patternString | 例外的url匹配模式,支持正则。 入参参考: |
custom-patternString | 匹配条件:指定常用类型,可选值为all或homepage 1. all:全部文件 2. homepage:首页 |
file-typeString | 匹配条件:文件类型,多个请以英文;分隔,可选值:gif png bmp jpeg jpg html htm shtml mp3 wma flv mp4 wmv zip exe rar css txt ico js swf m3u8 xml f4m bootstarp ts |
custom-file-typeString | 匹配条件:自定义文件类型,多个请以英文分号分隔。 |
directoryString | 目录 |
specify-urlString | 匹配条件:指定URL
入参不支持含http(s):// 开头的URI格式 |
request-methodString | 匹配的请求方式,可选值为:GET、POST、PUT、HEAD、DELETE、OPTIONS,多个请以英文分号分隔 |
*header-directionString | http头的控制方向,可选值为cache2visitor/cache2origin/visitor2cache/origin2cache,单选。
cache2origin是指回源方向---对应配置项回源请求;
cache2visitor是指回客户端方向—对应配置项回客户端应答;
visitor2cache是指接收客户端请求
origin2cache是指接收源应答
配置接收源应答方向,添加非CACHE control头,无法传递给客户端 |
actionString | http头的控制类型,支持http头部的增删改,可选值为add|set|delete,单选。对应header-name、header-value参数
1. add:表示新增一个头部,头部名称为header-name,头部值为header-value
2. set:表示修改指定头部header-name的值为header-value
3. delete:表示删除头部,header-name可同时配置多个
注意:优先级delete>set>add。当源站有对应响应头,则按源站响应的头部响应给客户端,此处新增的无效。 |
allow-regexpString | http头正则匹配,可选值:true/false。
true:表示对header-name的值按正则匹配方式处理
false:表示对header-name的值按实际入参处理,不做正则匹配。
不传默认是false |
header-nameString | http头名称,新增或修改http头,只允许输入一个;删除http头允许输入多个,以分号“;”隔开。
1.当action为add:表示新增这个header-name头部
2.当action为set:修改这个header-name头部的值
3.当action为delete:删除这个header-name头部
注意:对特殊http头的操作是受限的,允许操作的http头及操作类型请参看【概览】-【附件2: header操作】 |
header-valueString | http头域对应的值,例如:mytest.example.com
注意:
1. 当action为add或set时,该入参必须传值
2. 当action为delete时,该入参不用传
支持通过关键字获取指定变量值,如客户端ip,包含如下:
关键字:含义
#timestamp:当前时间,时间戳如1559124945
#request-host:请求头中的HOST
#request-url:请求url,包含协议域名等的全路径,如http://aaa.aa.com/a.html
#request-uri:请求uri,相对路径格式,如/index.html
#origin-ip:回源IP
#cache-ip:边缘节点IP
#server-ip:对外服务IP
#client-ip:客户端IP,即访客IP
#response-header{xxx}:获取响应头中的值,如#response-header{etag},获取response-header中的etag值
#header{xxx}:获取请求的http header中的值,如#header{User-Agent},是获取header中的User-Agent值
#cookie{xxx}:获取cookie中的值,如#cookie{account},是获取cookie中设置的account的值 |
request-headerString | 2匹配请求头,头部值支持正则,头和头部值用空格隔开,如:Range bytes=[0-9]{9,} |
*priorityString | 表示客户多组配置的优先执行顺序。数字越大,优先级越高。 不传参默认为10,不可清空 |
*except-file-typeString | 例外的文件类型 |
*except-directoryString | 例外的目录 |
*except-request-methodString | 例外的请求方式 |
*except-request-headerString | 例外的请求头 |
参数名称 | 描述 |
---|---|
http status codeInteger | httpstatus=202; 表示成功调用新增域名接口,可使用header中的x-cnc-request-id查看当前新增域名的部署情况 |
x-cnc-request-idString | 唯一标示的id,用于查询每次请求的任务 (适用全部接口) |
locationString | 用于访问该域名信息的URL,其中domain-id为我司云平台为该域名生成的唯一标示,其值为字符串。 |
codeString | 错误代码,当HTTPStatus不为202时出现,表示当前请求调用的错误类型 |
messageString | 响应信息,成功时为success |
错误代码(code) | 描述(message) | HTTP状态码 | 语义 |
---|---|---|---|
InvalidParameter | The request has null config with null data-id, please remove it. | 400 | 其他属性都为空,dataId不能为空 |
InvalidParameter | No visit-control-rules was specified. | 400 | header-modify-rules字段不存在 |
InvalidParameter | No path-pattern was specified. | 400 | path-pattern字段不存在 |
InvalidParameter | No header-direction was specified. | 400 | header-direction字段不存在 |
InvalidParameter | The parameters headerDirection {} is invalid. | 400 | header-direction不合法 |
InvalidParameter | No header-name was specified. | 400 | header-name字段不存在 |
InvalidParameter | The parameters headerNames size no equal one when action is add or set. | 400 | header-name在操作为新增或修改的时候大于1条 |
InvalidParameter | No action was specified. | 400 | action字段不存在 |
InvalidParameter | The parameters action {} is invalid. | 400 | action字段不合法 |
InvalidParameter | The parameters allowReg {} is invalid. | 400 | allowReg字段不合法 |
InvalidParameter | No header-value was specified. | 400 | 当action为add或set时,该入参必须传值 |
InvalidParameter | No header-value was not need. | 400 | 当action为delete时,该入参不用传 |
HeaderDirectionError | Header-direction can only select {0}. | 400 | 您自定义的头部(header-name),对应的方向(header-direction)只能为{0}。{0}见接口实际响应值。 |
ConfigError | Pick one of the following items: exceptional url mode, exception directory, exception file type - exception custom file type | 400 | 例外的URL模式、例外的文件类-例外的自定义文件类型、例外的目录三选一 |
ConfigError | Priority must be an integer not exceeding 7 digits | 400 | [优先级]必须是不超过7位的整数 |
ConfigError | Priority is required. | 400 | [优先级]必填 |
#!/bin/bash username="example_username" apiKey="example_apiKey" date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"` password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64` curl -i --url "https://open.chinanetcenter.com/api/config/headermodify/123344" \ -X "PUT" \ -u "$username:$password" \ -H "Date: $date" \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -d ' { "header-modify-rules":[ { "path-pattern": ".*", "request-header": "My-Http-Header .", "header-direction": "cache2visitor", "action": "add", "header-name": "My-Http-Header", "header-value": "#header{My-Http-Header}" }, { "path-pattern": "/def", "header-direction": "cache2visitor", "action": "set", "header-name": "Server", "header-value": "my_new_value" }, { "path-pattern": "/abc", "header-direction": "cache2visitor", "action": "delete", "header-name": "Via" } ] }'
HTTP/1.1 202 Accepted Date: Fri, 17 May 2017 06:33:26 GMT Content-Type: application/json;charset=utf-8 x-cnc-request-id:c54cbbb4-19fe-407a-930c-3988b62ed2fd {"message":"success"}