Page tree
Skip to end of metadata
Go to start of metadata

To add an HTTP caching rule, use the following request:

POST /cdn_resources/:cdn_resource_id/http_caching_rules.xml
POST /cdn_resources/:cdn_resource_id/http_caching_rules.json

XML Request example:

curl -i -X POST -u user:userpass -H 'Accept: application/xml' -H 'Content-type: application/xml' --url 'http://onapp.test/cdn_resources/:cdn_resource_id/http_caching_rules.xml'  -d '<rule><name>some_name</name><conditions><0><connective>if</connective><subject>url</subject><predicate>default</predicate><value></value></0><1><connective>and</connective><subject>cookie</subject><cookie></cookie><predicate>default</predicate><value></value></1><2><connective>and</connective><subject>param</subject><param></param><predicate>default</predicate><value></value></2><3><connective>and</connective><subject>header</subject><header></header><predicate>default</predicate><value></value></3></conditions><actions><0><act>force edge to cache</act><seconds></seconds></0><1><act>redirect client</act><url></url></1><2><act>set response header</act><header></header><value></value></2><3><act>set custom origin</act><value></value></3></actions></rule>'

JSON Request example:

curl -i -X POST -u user:userpass -H 'Accept: application/json' -H 'Content-type: application/json' --url 'http://onapp.test/cdn_resources/:cdn_resource_id/http_caching_rules.json' -d '{"rule": {"name":"some_name", "conditions":{"0":{"connective":"if", "subject":"url", "predicate":"default", "value":""}, "1":{"connective":"and", "subject":"cookie", "cookie":"", "predicate":"default", "value":""}, "2":{"connective":"and", "subject":"param", "param":"", "predicate":"default", "value":""}, "3":{"connective":"and", "subject":"header", "header":"", "predicate":"default", "value":""}}, "actions":{"0":{"act":"force edge to cache", "seconds":""}, "1":{"act":"redirect client", "url":""}, "2":{"act":"set response header", "header":"", "value":""}, "3":{"act":"set custom origin", "value":""}}}}'

Where:

name - name of the rule

conditions - the array of parameters of the conditions associated with the rule

connective - the connective by which the conditions are bonded, either 'and' or 'or'.

subject - the subject of the condition. The subject should be written using small letters only and with spaces between the words. For the list of subjects you can set for a rule refer to The List of Subjects.

predicate - the predicate of the condition. The predicate should be written using small letters only and with spaces between the words. For the list of predicates you can set for a rule refer to The List of Predicates.

value - the value against which the subject is compared.

header - the subject that selects the value of a specific client request header. If the request header does not exist, then the value “” is selected.

act - the action associated with the rule. The action should be written using small letters only and with spaces between the words. For the list of actions you can set for a rule refer to The list of Actions.

url - the subject that selects the URL part of the request. It excludes the query string.

cookie - the subject that selects the value of a specific cookie sent by the client.

param - the subject that selects the value of a specific query string parameter. If there are multiple identical keys, the last value is selected.

seconds - the time in seconds set for the action. For more information, refer to The list of Actions.

  • No labels