The Advanced Rules Engine can be used to dynamically change settings based on comparison rules on a per request basis.

If a rule is matched, it can change certain settings in the context of that request only. This allows for definition of specific behavior for specific situations.

Use the “Gear” button at Site Management screen to access the Advanced Rules Engine.

advanced-rules1

Overview

Each Rule consists of IF-THIS condition and DO-THAT consequence.

Running flow is following: When client’s request matches IF-THIS, then DO-THAT is applied.

This screen gives you an overview of the rules that have currently been set for this specific site and allows for the definition of new rules.

rules-overview

Rule creation basics

Use the “+ Add New Rule” button to start adding a new rule. This will create a new table line that you can customize into an effective rule by filling out the required items. The screen should look like this:

rules-new

As you can see IF-THIS condition contains Operand #1 dropbox, Operator dropbox and Input field for a Operand #2 value.

DO-THAT result contains Action dropbox and Value input for selected action.

Operand #1 list

Screen Shot 2016-04-22 at 10.26.31

Operators list

Screen Shot 2016-04-22 at 10.27.01

Actions list

Screen Shot 2016-04-22 at 10.26.54

In some cases of Operand #1 it’s mandatory to fill in specific Operand #1‘s value in a separate input field for rule to work.

For example, specify “Origin Header”‘s value like this:

subvalue

Multiple IF-THIS conditions

You can create multiple IF-THIS conditions for a single rule. To do it simply hit “Add more conditions” button

rules-new-condition

 

After that you may edit your next condition and define conditions boolean operator either “OR” or “AND”.

Once you have completed your rule you may press finish to save your rule in the list or press cancel to cancel.

Saving changes

Important: When you’re done editing all your rules in list you need to press save-all-rules at the bottom of the list for your new list to take effect.

Editing/Deleting Rules

These actions are pretty straightforward: you may edit existing rule by pressing button-edit-small or delete it from the list using button-trash-small.

Important: If for any reason you need no rules, you can delete all the rules from the list and press save-empty

Cook Book

To make your life even easier we’ve created a list of predefined Rules for the most frequent situations. You can pick them from our “Cook Book” by clicking cookbook

More details about CookBook recipes can be found in our Cook Book Documentation

Advanced documentation

Rule structure

Each rule consists of one or many IF-THIS Conditions followed by DO-THAT Actions.

Each Condition’s structure is following: {Operand #1} {Operator} {Operand #2}

When there is more then one condition, they are linked with boolean operator [OR|AND]

In pseudocode this can look like following:

IF (Condition [[AND|OR] Condition …]) DO [Action(Value)]

Operand #1

The values that can be used for operand1 are as follows:

The HTTP status code returned by the origin server for this file

Example: 200

Note: Only available if the file is already cached. Cannot cause an action against origin or path.

The value of a HTTP header returned by the origin server for this file

Example: application\json for origin_header.Content-Type

Note: Only available if the file is already cached. Cannot cause an action against origin or path.

The value of a http request header sent by the client

Example: en-US,en;q=0.8e for request_header.Accept-Language

The value of a URL querystring argument sent by the client

Example: 1 for querystring.something (e.g. url http://cdn.mysite.com/files/100MB.zip?something=1)

The full URL querystring argument sent by the client

Example: ?something=1&else=2

The HTTP request method sent by client

Example: GET

The file path and query as requested by client

Example: /files/100MB.zip?something=1

The protocol, host, file path and query as requested by client

Example: http://cdn.mysite.com/files/100MB.zip?something=1

The full origin URL

Example: http://www.mysite.com/files/100MB.zip

The path part of the origin URL

Example: /files/100MB.zip

The VOD type that the client is requesting to play while using VOD Transmuxing Mode

Example: hls

+-POP

The CDN POP which has received the client request

Example: lon

Options: ams, ash, atl, bud, chi, dal, fra, lax, lon, mad, mia, nyc, par, sea, sjo, sng, sto, tky

The GeoIP continent code of the CDN POP which has received the client request

Example: EU

Options: AS, EU, NA

The protocol which the client connected with

Example: http

Options: http, https, spdy

The value of the HTTP Referer request header

Example: http://www.yoursite.com/pages/page32.html

The value of the HTTP User-Agent request header

Example: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0ml

The GeoIP continent code for the IP of the client

Example: EU

The GeoIP country code for the IP of the client

Example: GB

The GeoIP region code for the IP of the client

Example: A9

The GeoIP city name for the IP of the client

Example: Basingstoke

The GeoIP postal code for the IP of the client

Example: RG22

The IP address of the client

Example: 82.34.9.97

A salted MD5 hash of the client IP address

Example: 257824f4319ceb5ee6c2852af4628cf6

A UUID which is unique to individual requests

Example: E4278217-15EF-4B6A-8B8A-515271DCF60D

Always perform the action (do not compare any operand1)

Operator

The values that can be used for operator are as follows

Operator: ==

Equals – Operand1 must match Operand2 exactly

Operator: !=

Not Equals – Operand1 must not match Operand2

Operator: ~

case-sensetive-pcre – Operand1 must match the regular expression defined in Operand2

Operator: ~*

case-insensetive-pcre – Operand1 must match the regular expression defined in Operand2 regardless of upper/lower case differences

Operator: !~

negative-case-sensetive-pcre – Operand1 must not match the regular expression defined in Operand2

Operator: !~*

negative-case-insensetive-pcre – Operand1 must not match the regular expression defined in Operand2 regardless of upper/lower case differences

Operand #2

In the case that operator is == or != then operand2 should be text to match
In the case of one of the regex operators, operand2 should be a regular expression
Tokens are supported e.g. if origin_url ~ ^/country-([a-z][a-z])/.* then whitelist = {$1}

Action

Change the origin

Example: http://alt.example.com

Change the origin path

Example: /images/alt-logo.png

Overwrite the querystring sent by client

Example: abcd=1234&efgh=5678

Add to the querystring sent by client

Example: abcd=1234

Change the allowed protocols

Example: https+spdy

Change the origin host header

Example: alt.mysite.com

Change the speed limit

Example: 1k

Change the limit_after value

Example: 1m

Change the time to keep this file in cache before checking the origin for changes

Example: 3600 or 0 to disable caching

Enable/disable using origin’s Cache-Control header

Example: 1 to enable or 0 to disable

Enable/disable using a stale file. The value is the number of seconds to allow a stale file past expiry

Example: -300 for 5 minutes or 1 to always allow

Change the blacklisted countries

Example: US

Change the whitelisted countries

Example: NL

Implicitly enable gzip for these file extensions (if the client supports gzip)

Example: txt,js,css

Explicitly enable or disable gzip for this file (if the client supports gzip)

Example: 0 or 1

Add these HTTP headers to the cdn response, comma separated for multiple headers

Example: X-Match: true

Copy these headers from origin response to cdn response, comma separated for multiple headers

Example: Expires

Copy all headers from origin response to cdn response

Example: 0 or 1

Remove these headers from the cdn response, comma separated for multiple headers

Example: ETag

Pass client request headers to Origin while caching

Example: 0 or 1

Add or change client’s request headers before request to origin

Example: Accept-Encoding: gzip

Remove client’s request headers before request to origin

Example: Accept-Encoding

+-Via

Add or rewrite the Via header for response

Example: 0 or 1

Client ip must match this or HTTP 403 – Forbidden is returned

Example: 45.76.90.232 but more useful in a rule as empty to block everyone

Disable or enable querystring in cache uniqueness

Example: 0 or 1

Disable or enable querystring in cache in origin request, but do not include in cache uniqueness

Example: 0 or 1

Disable or enable special handling for HTTP video streaming playlists

Example: 0 or 1

When httplive is 1 then expire playlists after this many seconds

Example: 10 or 0 to disable caching

Add this text to cache uniqueness, best used as a way to expire files based on file name

Example: jpg-v3

Add this text to cache uniqueness, best used as a way to expire files based on file name, append it to any existing salt

Example: jpg-v3

Content version, use to expire files matching the pattern

Example: 1234

+-TTL

Unix time stamp. If the current time is greater then HTTP 410 – Gone is returned

Example: 1412256560

Send a HTTP 301 redirect

Example: http://www.yoursite.com/redirected.html

Send a HTTP 302 redirect

Example: http://www.yoursite.com/redirected.html

Expire the file at this time

Example:

+-Log

Set the custom log value

Set or add to the custom log value

Leave a Reply

Your email address will not be published. Required fields are marked *