TrafficScript provides ‘if’ and ‘if/else’ statements for conditional execution. The condition is an expression, which is evaluated.
The return value of the expression determines whether the condition is ‘true’ or ‘false’:
- A non-zero number or non-empty string is ‘true’;
- A zero number or empty string is ‘false’.
For example:
if( $url == "/" ) {
log.info( "Access to home page" );
}
... or
if( $isAuthenticated ) {
pool.use( "local pool" );
} else {
log.info( "Unauthenticated user accessed the service" );
connection.close();
}
Read more: Collected Tech Tips: TrafficScript examples