All Products
Search
Document Center

Server Load Balancer:Logical functions

Last Updated:Apr 01, 2026

AScript provides six logical functions for building conditions in forwarding rules: and(), or(), not(), eq(), ne(), and null().

Quick reference

FunctionSignatureReturnsShort-circuit
andand(arg, ...) → Booleantrue if all args are trueStops at first false
oror(arg, ...) → Booleantrue if any arg is trueStops at first true
notnot(arg) → BooleanInverts truthiness of argN/A
eqeq(arg1, arg2) → Booleantrue if arg1 equals arg2N/A
nene(arg1, arg2) → Booleantrue if arg1 does not equal arg2N/A
nullnull(v) → Booleantrue if v is empty (array, dict, or empty string)N/A

and

ItemDescription
Syntaxand(arg, ...) → Boolean
DescriptionExecutes the AND logical operator. Supports short-circuit evaluation: when any argument evaluates to false, the remaining arguments are not evaluated.
ParameterOne or more values to evaluate. Data type: any type.
Return valuetrue if all arguments evaluate to true. false if any argument evaluates to false.
ExampleSee below.
if and($arg_mode, eq($arg_mode, 'set_header')) {
   add_rsp_header('USER-DEFINED-1','path1')
}
  • If the request includes the mode parameter and its value is set_header, the USER-DEFINED-1 response header is set.

  • If the request does not include the mode parameter, short-circuit evaluation stops execution. The eq comparison is not run, and USER-DEFINED-1 is not set because and() returns false.

or

ItemDescription
Syntaxor(arg, ...) → Boolean
DescriptionExecutes the OR logical operator. Supports short-circuit evaluation: when any argument evaluates to true, the remaining arguments are not evaluated.
ParameterOne or more values to evaluate. Data type: any type.
Return valuetrue if any argument evaluates to true. false if all arguments evaluate to false.
ExampleSee below.
if and($http_from, or(eq($http_from, 'wap'), eq($http_from, 'comos'))) {
    rewrite(concat('http://tech.com.cn/zt_d/we2015/', $http_from), 'enhance_redirect')
}
  • If the request includes the from header and its value is wap or comos, the HTTP 302 redirect returns and the request is redirected to http://tech.com.cn/zt_d/we2015/[wap|comos].

  • If the from header value is wap, short-circuit evaluation stops the eq('comos') check. or() returns true immediately.

not

ItemDescription
Syntaxnot(arg) → Boolean
DescriptionExecutes the NOT logical operator. undef and false evaluate to false; all other values evaluate to true.
ParameterExactly one value to evaluate. Data type: any type.
Return valuetrue if the argument is falsy (undef or false). false if the argument is truthy.
ExampleSee below.

Boundary behavior:

Inputnot() result
undef (variable not present)true
falsetrue
0false
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 does not include the key parameter, the request is denied and HTTP 403 is returned.

  • not($cookie_user): if the request does not include cookie_user, the request is denied. HTTP 403 and the response body not cookie user are returned.

  • not(0) returns false.

  • not(false) returns true.

eq

ItemDescription
Syntaxeq(arg1, arg2) → Boolean
DescriptionChecks whether two values are equal.
Parametersarg1: the first value. Data type: any type. arg2: the second value. Data type: same as arg1.
Return valuetrue if the two values are equal. false if they are not equal.
ExampleSee below.
key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}
  • If the request includes both the k1 and k2 parameters, the comparison operations run.

  • If the request does not include k1 or k2, short-circuit evaluation stops the comparisons.

  • eq(key1, $arg_k1): checks whether the value of k1 equals value1.

  • ne(key2, $arg_k2): checks whether the value of k2 does not equal value2.

  • The response body match condition is returned only when the request includes both k1 and k2, the value of k1 equals value1, and the value of k2 does not equal value2.

ne

ItemDescription
Syntaxne(arg1, arg2) → Boolean
DescriptionChecks whether two values are not equal.
Parametersarg1: the first value. Data type: any type. arg2: the second value. Data type: same as arg1.
Return valuetrue if the two values are not equal. false if they are equal.
ExampleSee below.
key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}
  • If the request includes both the k1 and k2 parameters, the comparison operations run.

  • If the request does not include k1 or k2, short-circuit evaluation stops the comparisons.

  • eq(key1, $arg_k1): checks whether the value of k1 equals value1.

  • ne(key2, $arg_k2): checks whether the value of k2 does not equal value2.

  • The response body match condition is returned only when the request includes both k1 and k2, the value of k1 equals value1, and the value of k2 does not equal value2.

null

ItemDescription
Syntaxnull(v) → Boolean
DescriptionChecks whether a value is empty. Returns true for an empty array, empty dictionary, or empty string. Returns false for all other types and non-empty values.
Parameterv: the value to check. Data type: array, dictionary, or string. Returns false for other data types.
Return valueData type: Boolean. See the boundary behavior table below.
ExampleSee below.

Boundary behavior:

Inputnull() result
Empty array ([])true
Non-empty arrayfalse
Empty dictionary ({})true
Non-empty dictionaryfalse
Empty string ('')true
Non-empty stringfalse
Other data typesfalse
d = []
say(null(d))
set(d, 1, 'v1')
say(null(d))
say(tostring(null('x')))
say(tostring(null('')))

Output:

true
false
false
true