All Products
Search
Document Center

CDN:EdgeScript built-in variables

Last Updated:Apr 01, 2026

EdgeScript built-in variables map directly to NGINX variables and give your scripts read-only access to request properties: the URI, query parameters, headers, cookies, client IP, and protocol details.

Built-in variables are read-only. Do not assign values to them.

The dollar sign ($) prefix identifies a variable as a built-in variable. You can omit the $ prefix if your business logic requires it.

Variable limit

A single script supports at most 200 variables. If your rule requires more, split the logic into multiple user-defined functions, each containing no more than 200 variables. See Split a function for an example.

Handling hyphens in variable names

Three built-in variables — $arg_{name}, $http_{name}, and $cookie_{name} — use a {name} placeholder for a query string key, request header field, or cookie field. Each handles hyphens differently:

VariableHyphen handling
$arg_{name}If {name} contains a hyphen, use req_uri_arg('{name}') instead. Example: req_uri_arg('example-demo') for ?example-demo=123
$http_{name}Replace hyphens with underscores. Example: $http_x_user_id for the X-USER-ID header
$cookie_{name}If {name} contains a hyphen, use req_cookie('{name}') instead. Example: req_cookie('example-demo') for cookie: example-demo=123

Built-in variables

VariableReturnsNGINX variable
$arg_{name}Value of the {name} key in the query string$arg_
$http_{name}Value of the {name} field in the request header$http_
$cookie_{name}Value of the {name} field in the request cookie header$cookie_
$schemeProtocol type$scheme
$server_protocolProtocol version$server_protocol
$hostOriginal host$host
$uriOriginal URINone
$argsAll query string parameters, excluding the leading ?$args
$request_methodRequest method$request_method
$request_uriFull request URI, equivalent to uri + '?' + args$request_uri
$remote_addrClient IP address used to connect to the points of presence (POPs)$remote_addr

Example: $arg_{name} and $args

For the request http://example.aliyundoc.com/1k.file?k1=v1&k2=v2:

  • $arg_k1 returns v1

  • $args returns k1=v1&k2=v2 (the full query string, without ?)

Splitting function

When a rule contains more than 200 variables, split the original function into multiple user-defined functions. Each user-defined function must contain no more than 200 variables.

#If variables exceed the limit, split them like this:
def judeg_arg() {
  #Parameter judgment related logic
  x
  x
}

def judeg_time() {
  #Time judgment related logic
  x
  x
}

def judeg_token() {
  #Encryption judgment related logic
  x
  x
}

judeg_arg()
judeg_time()
judeg_token()