HTTP Application Rewrite Rule
Get HTTP application rewrite rule
Description
Get the rewrite rule of the HTTP application.
URI
GET /admin-api/applications/phases/rewrite/rules
JSON body
enable_rule
type: boolean
description: whether to enable the rule.
locked_rule
type: boolean
description: whether lock this rule for users from edge admin (cannot be edited and deleted)
top
type: integer
description: the order of the current rule in the rule chain, default is 0. The larger the value, the higher the ranking.
order
type: integer
description: the order of the current rule in the rule chain, default is 0. The smaller the value, the higher the ranking.
last
type: boolean
description: when the value is ’true’, the rule will be at the last of rule chains.
comment
type: string
description: the comment info for the rule.
conditions
type: array
description: the prerequisites for the rule.
conditions[*].variable
type: object
description: TODO
conditions[*].caseless
type: boolean
description: ignore case when comparing string
conditions[*].operator
type: enum
description: operator for comparing between conditions and values. legal operators: ==, ‘!=’, <, <=, ‘>’, ‘>=’, eq, ne, lt, le, gt, ge, ‘!~~ ‘, ‘~~’, contains, contains-word, prefix, suffix, ‘!contains’, ‘!contains-word’, ‘!prefix’, ‘!suffix’, ‘is-empty’, ‘!is-empty’,
conditions[*].values
type: array
description: values for comparing with conditions
conditions[].values[].type
type: enum
description: type for value. legal types: str, rx, wc, netaddr, uv, global-uv.
conditions[*].ip_list
type: array
description: reference global IP list by id.
conditions[].ip_list[]
type: int
description: id of global_ip_list.
actions
type: array
description: actions to be performed in the rules.
actions[*]
type: object
description: TODO
waf
type: object
description: the waf rule.
content
type: object
description: content of the response, now supports setting the favicon and empty_gif.
content.favicon
type: integer
description: the id of the favicon uploaded in the global config.
content.empty_gif
type: boolean
description: when the value is ’true’, will response a empty_gif.
proxy
type: object
description: the proxy rule.
cache
type: object
description: the cache setting of the rule.
cache.enforce_cache
type: boolean
description: whether to enforce the server to cache the content, ignoring the cache headers from the origin site.
cache.default_ttls
type: array
description: default cache ttls for origin site that have no cache rules according to the upstream response code.
cache.default_ttls[*]
type: object
cache.default_ttls[*].ttl
type: integer
description: Time-To-Live of the cache rule.
cache.default_ttls[*].ttl_unit
type: enum
description: the unit of the ttl, can be one of ’s’ / ‘min’ / ‘hour’ / ‘day’
cache.cluster_hash
type: boolean
description: whether enable the cluster hash
cache.disable_convert_head
type: boolean
description: we convert the HEAD request into a GET request to check the cache, when
disable_convert_head
is true, the conversion does not happen.cache.cache_key
type: object
description: the cache key of the resources.
cache.enable_global
type: boolean
description: whether the current resource is shared cache in the global application scope, by default the resource is shared cache in the scope of the current application.
cache.browser_ttl
type: integer
description: modify the standard cache ttl for browser.
cache.browser_ttl_unit
type: enum
description: the unit of the browser_ttl_unit, can be one of ’s’ / ‘min’ / ‘hour’ / ‘day’.
user_code
type: string
required: no
description: user defined edgelang code for the application.
Example Request
curl \
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
https://{admin-site}/admin-api/applications/http/1/phases/rewrite
Example Response
Status: 200 OK
{
"status": 0,
"data": [
{
"_modified_unix": 1617248472.0224,
"_created_unix": 1617084623.9334,
"order": 1,
"last": false,
"top": 0,
"waf": {
"rule_sets": [
7,
8,
6
]
},
"enable_rule": true,
"id": 1,
"locked_rule": true,
"comment": ""
}
]
}
update HTTP application rewrite rule
URI
PUT /admin-api/applications/http/{app_id}/phases/rewrite/rules/{rule_id}
JSON Body Parameters
{
"waf": {
"rule_sets": [
7,
8,
6
]
},
"enable_rule": true,
"locked_rule": true,
"comment": "modify the rule"
}
Example Request
Shell
curl -X PUT \
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules/1 \
-d '{
"comment": "modify the rule"
}'
Example Response
Status: 200 OK
{"status": 0}
Create HTTP application rewrite rule - user agent is mobile
Description
Create HTTP application rewrite rule - limit request rate
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"sleep",
"sleep":{
"time":1
}
}
],
"conditions":[
{
"variable":{
"name":"ua-is-mobile",
"args":"",
"user_var":null,
"global_var":null
},
"operator":{
"name":"is-true" // is-true, !is_true
},
"values":null, // no need values
"number":2
}
],
"waf":null,
"proxy":null,
"cache":null,
"content":null,
"last":false,
"comment":"",
"order":1
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"sleep","sleep":{"time":1}}],"conditions":[{"variable":{"name":"ua-is-mobile","args":"","user_var":null,"global_var":null},"operator":{"name":"is-true"},"values":null,"number":2}],"waf":null,"proxy":null,"cache":null,"content":null,"last":false,"comment":"","order":1}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}
Create HTTP application rewrite rule - limit request rate
Description
Create HTTP application rewrite rule - limit request rate
- If the request does not exceed the
rate_shape
limit, we accept all new requests without any delay. - If the request exceeds the
rate_shape
limit but not therate_reject
limit, we delay any new requests. - If the request exceeds the
rate_reject
limit, we reject any new requests.
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"limit-req-rate",
"limit-req-rate":{
"limit_key":"client-addr", // client-addr, uri, uri-arg, req-cookie, first-x-forwarded-addr, last-x-forwarded-addr
"rate_shape":1,
"rate_shape_unit":"r/s",
"rate_reject":1,
"rate_reject_unit":"r/s",
"reject_action":"close_connection", // enable_hcaptcha, enable_edge_captcha, error_page, close_connection
"error_page_status_code":400,
"hcaptcha_clearance_time":60, // cache time after hcaptcha validation pass
"edge_captcha_clearance_time":60 // cache time after edge captcha validation pass
}
}
],
"conditions":[
],
"waf":null,
"proxy":null,
"cache":null,
"content":null,
"last":false,
"comment":"",
"order":3
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"limit-req-rate","limit-req-rate":{"limit_key":"client-addr","rate_shape":1,"rate_shape_unit":"r/s","rate_reject":1,"rate_reject_unit":"r/s","reject_action":"close_connection","error_page_status_code":400,"hcaptcha_clearance_time":60,"edge_captcha_clearance_time":60}}],"conditions":[],"waf":null,"proxy":null,"cache":null,"content":null,"last":false,"comment":"","order":3}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}
Create HTTP application rewrite rule - enable-gateway-brotli
Description
Enable gateway brotli compression.
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"enable-gateway-brotli",
"enable-gateway-brotli":{
"enabled": true
}
}
]
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"enable-gateway-brotli","enable-gateway-brotli":{"enabled":true}}]}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}
Create HTTP application rewrite rule - set-brotli-types
Description
Enable on-the-fly brotli compression of responses for the specified MIME types.
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"set-brotli-types",
"set-brotli-types":{
"types": ["text/plain", "text/html"]
}
}
]
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"set-brotli-types","set-brotli-types":{"types":["text/plain","text/html"]}}]}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}
Create HTTP application rewrite rule - enable-gateway-gzip
Description
Enable gateway gzip compression.
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"enable-gateway-gzip",
"enable-gateway-gzip":{
"enabled": true
}
}
]
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"enable-gateway-gzip","enable-gateway-gzip":{"enabled":true}}]}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}
Create HTTP application rewrite rule - set-gzip-types
Description
Enable on-the-fly gzip compression of responses for the specified MIME types.
URI
POST /admin-api/applications/http/{app_id}/phases/rewrite/rules
JSON body
{
"actions":[
{
"type":"set-gzip-types",
"set-gzip-types":{
"types": ["text/plain", "text/html"]
}
}
]
}
Example Request
Shell
curl 'https://{admin-site}/admin-api/applications/http/1/phases/rewrite/rules'\
-H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"actions":[{"type":"set-gzip-types","set-gzip-types":{"types":["text/plain","text/html"]}}]}'
Example Response
Status: 200 OK
{"status":0,"data":{"id":1}}