vADC Docs

HowTo: TrafficScript rules processing and flow control

by on ‎02-24-2013 05:44 AM - edited on ‎06-04-2015 04:18 PM by PaulWallace (2,183 Views)

A virtual server may be configured to run several request or response rules. In this case, the rules are executed in turn, unless a terminal action such as connection.close() or pool.use() is called.

 

Quite often, it's necessary to stop processing a rule and proceed to the next rule. For example, you might have a lengthy rule which only applies to responses that are HTML documents (i.e., not images or other response types):

 

$contenttype = http.getResponseHeader( "Content-Type" );  
if( string.startsWith( $contenttype, "text/html" ) ) {  
  ...  
  ...  
  ...  
}

 

It's more elegant to use the 'break' statement to stop processing the current rule if the condition is not met:

 

$contenttype = http.getResponseHeader( "Content-Type" );  
if( !string.startsWith( $contenttype, "text/html" ) ) break;  
...  
...  
...  

 

You can also use the 'continue' statement to restart the current rule.

 

Read more: Collected Tech Tips: TrafficScript examples

Contributors