Expressions in Arnica NanoProxy rules

July 14, 2022 by Igor Lozhkin
Rules are usually applicable to request components which can be referenced as:

.Path[n] - path component, 0 based
.Query[str] - query string parameter
.Header[str] - HTTP request header 
.Cookie[str] - cookie
.PathStr - complete path
.Scheme - URI scheme
.HostName - host name in the URI
.QueryStr - complete query string
.Host - host with port
.Fragment - URI fragment
.Port - port number, if present in URI

For example, when the first component of URI path is home, the request is rewritten to execute Arnica WebPortal container page as in this example:

 [[rule=match home]]
action=rewrite
match_path[0]=home
uri={{.Scheme}}://{{.HostName}}/webportal/output/proxy.aspx?method=loadpage&resourcecode=web_site_home_page

The "match_path[nn]' in this example is a rule operator against the first (in 0-based indexing) component of the path. 

The {{.Scheme}} is an example of an evaluatable expression.

The following are supported operands:

match_path[n] - match n-th path components, referenced by 0-based index
match_query[s] - match value of specified query string parameter
match_header[s] - match value of specified HTTP request header
match_cookie[s] - match value of specified cookie
match_method - match value of specified HTTP method of the request
not_match_path[n] - do not match n-th path components, referenced by 0-based index
not_match_query[s] - do not match value of specified query string parameter
not_match_header[s] - do not match value of specified HTTP request header
not_match_cookie[s] - do not match value of specified cookie
not_match_method - do not match value of specified HTTP method of the request
match_path_words_lt - number of path components must be less than specified number 
match_path_words_gt - number of path components must be greater than specified number 

String-based operands (i.e. except the last two) can reference value with wildcards ? (specific symbol) and * (any symbol, including no symbols), and use case-insensitive comparison. 

Multiple condition expressions with mentioned above operands may be included, and if multiple expressions are included, they are logically connected with AND operand, i.e. all conditions must be met to trigger the rule action.

To trigger action against something empty, for example when path is empty, the following conditions can be used:

not_match_path[0]=?*