Forum Discussion

Wes_98712's avatar
Wes_98712
Icon for Nimbostratus rankNimbostratus
Jul 05, 2012

iRule Order Evaluation

I've got a datagroup that I reference in an iRule that matches any request that starts with /api and sends it to a different pool. This same datagroup has other URI paths that I reference to determine if an SSL redirect needs to occur.

I am changing the iRule to send all /api requests to a new pool if a flag is set, as I want to be able to simply flip a flag on or off to redirect traffic appropriately. I don't want to take the /api out of the datagroup as I want the ability to use a variable flag to flip the new pool on or off depending on what is going on.

My concern is, in the following if/else/then block will the first line evaluate true or the second? In other words, does the TCL language read through the entire block before it takes action? Or does it take action based on the first condition that matches? In both lines (the /api and $myapiflag) as well as the class match $myluri, rule is true because /api exists in both the datagroup. I want the first line to be evaluated only if the uri starts with api and the flag is set.

when HTTP_REQUEST {

set myhost [HTTP::host]

set myuri [HTTP::uri]

set myluri [string tolower $myuri]

set myapiflag 0

if { $myluri starts_with "/api" && $myapiflag } {

pool api.pool.com_8080

} elseif { [class match $myluri starts_with clients_noredirect_class]} {

pool clients.pool.com_80

} elseif { $myhost equals "" } {

if { [class match $myluri starts_with clients_noredirect_class] } {

pool app.pool.com_80

}

} else {

HTTP::redirect ""

}

}

4 Replies

  • not sure if i understand question correctly. anyway, pool api.pool.com_8080 will be selected only if $myluri starts_with "/api" AND $myapiflag is set (not equal to 0).
  • Nitass that is exactly what I am asking. If both lines evaluate as true, which one is selected? The first or the second?
  • Wes, for the first successful test, that code block will be executed and then processing will halt for anything else in the elseif/else tests.