Forum Discussion
iRule Switch Statement default pool
Trying to understand how this irule should behave when it hits the "default' option on the "switch" statement. When the "pool $default_pool" is called what is the behaviour of the pool statements that follow in the "if then" statement? Does it override the previous pool statement?
when CLIENT_ACCEPTED {
set default_pool prod_default3_pool
set inbound_temp_pool prod_temp3_pool
}
when HTTP_REQUEST
{
switch -glob [string tolower [HTTP::uri]]
{
"/foo*"
{
drop
}
"/bar*"
{
pool bar_pool
persist cookie insert "barsession" "1d 00:00:00"
}
}
default
{
pool $default_pool
if { [HTTP::cookie exists "TEMP"] }
{
pool $inbound_temp_pool
}
else
{
}
}
- rob_carrCirrocumulus
You have some syntax problems with your iRule, namely unbalanced closing braces and an empty else statement. I've fixed those below.
when CLIENT_ACCEPTED { set default_pool prod_default3_pool set inbound_temp_pool prod_temp3_pool } when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/foo*" { drop } "/bar*" { pool bar_pool persist cookie insert "barsession" "1d 00:00:00" } default { pool $default_pool if { [HTTP::cookie exists "TEMP"] } { pool $inbound_temp_pool } } } }
In a switch statement, the 'default' option handles anything that haven't matched one of the configured comparisons. In your rule, that means any request with a URI not beginning with /foo or /bar will fall to the default case and end up assigned to the pool specified by $default_pool...except when the request contains the HTTP cookie "TEMP", in which case, the connection is assigned to the pool specified by $inbound_temp_pool.
As written, your rule is setting the variables default_pool and inbound_temp_pool on each new connection, which is probably not needed. You might want to move that variable assignment out to the RULE_INIT event, or even get rid of the assignment entirely and directly name the pools.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com