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 Splitting 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:
Variable | Hyphen handling |
| If |
| Replace hyphens with underscores. Example: |
| If |
Built-in variables
Variable | Returns | NGINX variable |
| Value of the |
|
| Value of the |
|
| Value of the |
|
| Protocol type |
|
| Protocol version |
|
| Original host |
|
| Original URI | None |
| All query string parameters, excluding the leading |
|
| Request method |
|
| Full request URI, equivalent to |
|
| Client IP address used to connect to the points of presence (POPs) |
|
Example: $arg_{name} and $args
For the request http://example.aliyundoc.com/1k.file?k1=v1&k2=v2:
$arg_k1returnsv1$argsreturnsk1=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()