12. Lua Scripting

Configuration Definition: Subscriber
Configuration Application: Match Rule
Default Behavior: Off/Disabled
Version: 18.4
SelfService: NO

The CTL CDN supports the ability to execute Lua scripts in the request and/or response path. Lua provides extensive capabilities beyond manipulating the requests and responses. Given the power that Lua provides, all scripts are currently developed by CTL CDN support on a per-case basis.

Once a Lua script is developed by CTL CDN Support, it will appear in the customer’s service image as a definition. It can be referenced by a match rule, but cannot be modified by the subscriber. In general, the actual script will be visible and will include CTL-specific Lua bindings that are not part of the standard Lua language. Lua scripts are represented in the service image as a JSON definition as shown below:

"luaDefinitions": [
        {
            "heavy": false,
            "direction": "Response",
            "script": "-- Get local table references.
                       local leapfrog = leapfrog
                       local fphttp = fphttp

                       -- Get the response object from the transaction.
                       local resp = leapfrog.get_response(txn)

                       -- Check for 403 and turn it into 401 if present.
                       if fphttp.get_status(resp) == 403 then
                       fphttp.set_status(resp, 401)
                       end

                       -- All done!",
            "id": 1,
            "name": "Lua_Response",
            "signature": "123456789abcwxyz"
        }

Note that once a Lua definition is added to a service image, it will continue to be available in future versions and be included in service images copied from one with the Lua script present at the time the copy was made. When requesting a Lua script, it is important to inform CDN Support which service images it should be included in.

Once a Lua script is defined, it can be attached to a match rule. The match rule determines which objects are subject to the Lua script. Following is a sample match rule using a Lua definition:

"matchGroups": [
  {
    "id": 8456,
    "matchRules": [
      {
        "expression": "/softInv",
        "features": {
          "lua": {
            "value": {
              "idList": [
                1
              ]
            }
          }
        }
      }
    ]
  }
]

It is also possible to create a Global Lua policy. Such a policy applies to all requests for a given set of Aliases under a common ReportingID (AKA Property). This is done by attaching the Lua Script to a Match Rule within the Global Match Set (ID: 0).

"matchGroups": [
  {
    "id": 0,
    "matchRules": [
      {
        "expression": "$id.minor == 59468",
        "features": {
          "globalLua": {
            "value": {
              "idList": [
                594680
              ]
            }
          }
        }
      }
    ]
  }
]