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:
| Variable | Hyphen 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
| Variable | Returns | NGINX 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_ |
$scheme | Protocol type | $scheme |
$server_protocol | Protocol version | $server_protocol |
$host | Original host | $host |
$uri | Original URI | None |
$args | All query string parameters, excluding the leading ? | $args |
$request_method | Request method | $request_method |
$request_uri | Full request URI, equivalent to uri + '?' + args | $request_uri |
$remote_addr | Client 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_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()