vADC Docs

HowTo: if-then-else conditions in TrafficScript

by on ‎02-24-2013 05:33 AM - edited on ‎06-04-2015 04:11 PM by PaulWallace (2,280 Views)

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

Contributors