Overview

Property configuration rules use behaviors that state a course of action defined by options and criteria that trigger the action.

Behaviors

Within rules, your behaviors are represented as an array of objects, each object a single behavior with its options.

Default rule behaviors

The default rule is the required base rule. Behaviors you set at the default rule level apply to all requests for your property hostnames unless another rule overrides the settings.

For example, a default rule has two behaviors, origin and cpCode. For all the property's hostnames, the behavior of the origin and CP code is governed by the defined options.

"rules": {
  "name": "default",
  "behaviors": [
    {
      "name": "origin",
      "options": {
        "originType": "CUSTOMER",
        "hostname": "example.com",
        "forwardHostHeader": "REQUEST_HOST_HEADER",
        "cacheKeyHostname": "ORIGIN_HOSTNAME",
        "compress": true,
        "tcipEnabled": false,
        "httpPort": 80
      }
    },
    {
      "name": "cpCode",
      "options": {
        "value": {
          "id": 12345,
          "name": "main site"
        }
      }
    }
  ]
}

Child rules

Behaviors for child rules are structured the same but are nested within the child rule.

Here, a child rule of Compress Text Content has a behavior of gzipResponse with an option.

"children": [
    {
      "name": "Compress Text Content",
      "behaviors": [
        {
          "name": "gzipResponse",
          "options": { "behavior": "ALWAYS" }
        }
      ]
    }
  ]

Criteria

Criteria are the situational conditions that trigger a behavior's action. You can have criteria for any rule at any level of your rule tree.

In the above compress text content rule, the behavior is set to always zip the content, but if not all content types fit the rule, it's the criteria that set the types that do.

"criteria": [
  {
    "name": "contentType",
    "options": {
      "matchOperator": "IS_ONE_OF",
      "matchWildcard": true,
      "matchCaseSensitive": false,
      "values": [
        "text/html*",
        "text/css*",
        "application/x-javascript*"
      ]
    }
  }
]

Complete tree

Your property configuration, rules, child rules, and their behaviors and criteria, work together as a rule tree to shape a solution.

The sample code presented works together to deliver a solution that uses a customer's origin as the source of truth, its hostname to build out the keys for cached content, and directs requests for information through port 80.

The solution also collects all forwarded request metadata and compresses specific content types to reduce the amount of data sent in responses and increase display speed.

"rules": {
  "name": "default",
  "options": {
      "is_secure": false
  },
  "behaviors": [
    {
      "name": "origin",
      "options": {
        "originType": "CUSTOMER", 
        "hostname": "example.com", 
        "forwardHostHeader": "REQUEST_HOST_HEADER", 
        "cacheKeyHostname": "ORIGIN_HOSTNAME", 
        "compress": true, 
        "enable_true_client_ip": false,
        "httpPort": 80 
      }
    },
    {
      "name": "cpCode", 
      "options": {
        "value": {
            "id": 12345, //my code
            "name": "main site"
        }
      }
    }
  ],
  "children": [
    {
      "name": "Compress Text Content",
      "behaviors": [
        {
          "name": "gzipResponse",
          "options": { "behavior": "ALWAYS" }
        }
      ],
      "criteria": [
        {
          "name": "contentType",
          "options": {
            "matchOperator": "IS_ONE_OF",
            "matchWildcard": true,
            "matchCaseSensitive": false,
            "values": [
              "text/html*",
              "text/css*",
              "application/x-javascript*"
            ]
          }
        }
      ]
    }
  ]
}