All Products
Search
Document Center

Edge Security Acceleration:Logical functions

Last Updated:Jun 16, 2026

EdgeScript (ES) provides six logical functions for building conditional expressions in CDN rules: and, or, not, eq, ne, and null. The three Boolean operators (and, or, not) support short-circuit evaluation, so the engine stops evaluating arguments as soon as the result is determined.

Function summary

FunctionSignatureShort-circuitReturns
andand(arg, ...) : BooleanStops on first falsetrue if all args are true
oror(arg, ...) : BooleanStops on first truetrue if any arg is true
notnot(arg) : BooleanInverted Boolean
eqeq(arg1, arg2) : Booleantrue if equal
nene(arg1, arg2) : Booleantrue if not equal
nullnull(v) : Booleantrue if v is an empty string, empty array, or empty dictionary

and

Signature: and(arg, ...) : Boolean

Executes the AND logical operator. When any argument evaluates to false, short-circuit evaluation stops and the remaining arguments are skipped.

Parameters: One or more values of any type.

Return value: true if all values evaluate to true; false if any value evaluates to false.

Example: Set a response header only when a specific query parameter is present and matches a given value.

if and($arg_mode, eq($arg_mode, 'set_header')) {
   add_rsp_header('USER-DEFINED-1','path1')
}
  • If the request includes mode=set_header, and() evaluates both conditions and returns true. The USER-DEFINED-1 response header is set.

  • If the request has no mode parameter, $arg_mode evaluates to false. Short-circuit evaluation stops — eq() is never called — and the response header is not set.

or

Signature: or(arg, ...) : Boolean

Executes the OR logical operator. When any argument evaluates to true, short-circuit evaluation stops and the remaining arguments are skipped.

Parameters: One or more values of any type.

Return value: true if any value evaluates to true; false if all values evaluate to false.

Example: Redirect requests based on the value of the From header.

if and($http_from, or(eq($http_from, 'wap'), eq($http_from, 'comos'))) {
    rewrite(concat('http://example.com.cn/zt_d/we2015/', $http_from), 'enhance_redirect')
}
  • If the From header is wap or comos, the request is redirected (HTTP 302) to http://example.com.cn/zt_d/we2015/[wap|comos].

  • If the From header is wap, or() returns true immediately — the comos check is skipped.

not

Signature: not(arg) : Boolean

Executes the NOT logical operator. The values of undef and false evaluate to false, and other values evaluate to true.

Parameter: Exactly one value of any type.

Return value: true or false.

Example: Block requests that are missing required parameters or cookies.

if not($arg_key) {
    exit(403)
}
if not($cookie_user) {
    exit(403, 'not cookie user')
}
if not(0) {
    exit(403)
}
if not(false) {
    exit(403)
}
  • not($arg_key) — if the request has no key query parameter, $arg_key is undef. not(undef) returns true, and the request exits with HTTP 403.

  • not($cookie_user) — if the request has no cookie_user cookie, $cookie_user is undef. not(undef) returns true, and the request exits with HTTP 403 with the body not cookie user.

  • not(0) — returns false. The block does not execute.

  • not(false)false is falsy, so not(false) returns true. The block executes and exits with HTTP 403.

eq

Signature: eq(arg1: any, arg2: same type as arg1) : Boolean

Compares whether two values are equal.

Parameters:

  • arg1: The first value. Data type: any.

  • arg2: The second value. Data type: same as arg1.

Return value: true if the two values are equal; false otherwise.

Example: The following example combines eq and ne inside an and() call. See the ne section for the full explanation.

key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}

ne

Signature: ne(arg1: any, arg2: same type as arg1) : Boolean

Compares whether two values are not equal.

Parameters:

  • arg1: The first value. Data type: any.

  • arg2: The second value. Data type: same as arg1.

Return value: true if the two values are not equal; false otherwise.

Example: Match a request only when both query parameters are present and meet specific value conditions.

key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}

All four conditions must be true for the body to execute:

  1. The request includes the k1 parameter.

  2. The request includes the k2 parameter.

  3. The value of k1 equals value1 (checked by eq).

  4. The value of k2 does not equal value2 (checked by ne).

If the request is missing k1 or k2, short-circuit evaluation stops at step 1 or 2, and neither eq() nor ne() is called.

null

Signature: null(v: array | dictionary | string) : Boolean

Checks whether a data type is specified for EdgeScript (ES).

Parameter: v — an array, dictionary, or string. Passing any other data type returns false.

Return value: Boolean.

  • true — if v is an empty string, or an array or dictionary with no elements.

  • false — if v is a non-empty string, a non-empty array or dictionary, or any other data type.

Example:

d = []
say(null(d))
set(d, 1, 'v1')
say(null(d))
say(tostring(null('x')))
say(tostring(null('')))

Output:

true
false
false
true
  • null(d) on an empty array [] returns true.

  • After set(d, 1, 'v1'), the array is non-empty, so null(d) returns false.

  • null('x') — non-empty string — returns false.

  • null('') — empty string — returns true.