Data fields
Operators
LHS stands for left-hand side of the operation, RHS stands for right-hand side of the operation.
Equality
LHS == RHS- returnstrueif both sides are equalLHS != RHS- returnstrueif both sides are different
Numerical
WhenLHS and RHSare numerical values.
LHS < RHS- returnstrueifLHSis less thanRHSLHS > RHS- returnstrueifLHSis more thanRHSLHS <= RHS- returnstrueifLHSis less than or equal toRHSLHS >= RHS- returnstrueifLHSis more than or equal toRHS
Logical
WhenLHS and RHSare boolean values.
!LHS- returns the opposite boolean value ofLHSLHS && RHS- returnstrueif bothLHSandRHSaretrueLHS || RHS- returnstrueif eitherLHSorRHSaretrue
Strings
WhenLHS and RHSare strings.
LHS contains RHS- returnstrueifRHSis a contained inLHSLHS not contains RHS- returnstrueifRHSis not contained inLHS
RegEx matching
WhenLHS is a string, and RHS is a string literal with a RegEx pattern. Pattern needs to be enclosed with backticks (`).
LHS matches RHS- returnstrueifLHSmatches the regular expression in theRHSLHS not matches RHS- returnstrueifLHSdoes not match the regular expression in theRHS
Arrays
WhenLHSis an array.
LHS in RHS- returnstruewhetherLHSis in (or belongs to)RHSLHS not in RHS- returns the opposite ofLHS in RHSLHS[RHS]- returns the value at numeric indexRHSin the arrayLHS, returnsnilfor missing values
Objects
WhenLHSis an object.
LHS in RHS- returnstruewhetherLHSis in (or belongs to)RHS:LHS not in RHS- returns the opposite ofLHS in RHS.LHS[RHS]- returns the value at string fieldRHSin the objectLHS. Returnsnilfor missing valuesLHS.RHSis equivalent toLHS[RHS]whereLHSis anobject, andRHSis an unquotedstringliteral that can be used as an identifier.
http.requestis equivalent tohttp["request"].http.request.headers.origin.0produces an error because the unquotedstringliteral0cannot be used as an identifier.
Functions and custom data types
Describes additional functions and special data types available during rule evaluation.Strings
upper(string) -> string- transforms the string to all uppercase characterslower(string) -> string- - transforms the string to all lowercase charactersstarts_with(source string, substring string) -> boolends_with(source string, substring string) -> bool
HTTP headers
The Custom Typehttp_headers behaves similar to an object, but it’s keys are normalized to be in MIME Header format in all operations (so usage is case-insensitive), and its values are of type array and contain the values for the given header name, preserving the original order. Examples:
- Check if a header was set:
"cOnTeNt-TyPe" in http.request.headers - Get the first cookie that was set:
http.request.headers["accept"][0]
IP address and CIDR
The Custom Typeip represents an IPv4 or IPv6 address.
The Custom Type cidr represents an IPv4 or IPv6 CIDR range.
cidr(string) -> cidrparses an IPv4 or IPv6 CIDR.- The
inoperator can be used to check if anipis in a givencidr.
- The
- Check if IP address belongs to a CIDR range:
http.request.ip in cidr("1.1.1.1/10")
Semantic versioning
semver_is_valid(string) -> bool- checks if given string is a valid semver stringsemver_compare(s1, s2) -> int- compares two semver strings- returns
-1ifs2 < s1,1ifs2 > s1, or0if they are equal
- returns