vADC Docs

HowTo: TrafficScript Syntax

by on ‎02-24-2013 06:29 AM - edited on ‎06-02-2015 04:12 PM by PaulWallace (2,856 Views)

TrafficScript is a simple, command-based language. A command is called a 'statement', and each statement is terminated with a ';'. Comments begin with a '#' symbol, and finish at the end of the line:


# Store the value '2' in the variable named $a  
$a = 2;  
# call the 'connection.close' function  


Variables are indicated by the '$' symbol. There is no typing in TrafficScript, and you do not need to pre-declare a variable before you use it. Variables are not persistent - they go out of scope when a rule completes.


You can use variables in expressions to calculate new values (numbers and strings). Common mathematical, comparison and boolean operators are available, and '.' is used to concatenate strings.


# Set the value of $a to 1.75  
$a = 1 + 1/2 + 0.25;  
# create a new string with the '.' operator  
$fullname = $firstname . " " . $lastname;  


Functions are called using the normal bracket-and-argument-list syntax, and many functions can take different numbers of arguments. Function names often contain two or three parts, separated by '.'; this conveniently groups functions into different families.


$path = http.getPath();  
$cookie = http.getCookie( "ASPSESSIONID" );  
$browser = http.getHeader( "User-Agent" ); 


TrafficScript also provides data structures in the form of arrays and hashes. Arrays and hashes allow you to store multiple values in one TrafficScript structure. For more information, see the HowTo: TrafficScript Arrays and Hashes article.


Read more