Forum Discussion
nitass
Sep 02, 2013Employee
will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
you have to repeat [string tolower [HTTP::header User-Agent]] (or set it to variable first and re-use it later) in if-condition.
e.g.
set uagent [string tolower [HTTP::header User-Agent]]
if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"} {
or you may use switch instead of if-condition.
e.g.
[root@ve11a:Active:Not All Devices Synced] config tmsh list ltm rule myrule
ltm rule myrule {
when HTTP_REQUEST {
switch -glob [HTTP::header value "User-Agent"] {
"*MSIE 6*" -
"*MSIE 7*" -
"*MSIE 8*" {
pool qux
}
default {
pool [LB::server pool]
}
}
}
}
- mbamusa_59409Sep 03, 2013NimbostratusThank you Nitass , is the below OK ? set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"}{ pool Pool1 } else { pool Pool2 } }
- nitassSep 03, 2013Employeeit looks okay to me.
- Colin_Walker_12Sep 04, 2013Historic F5 AccountThat looks logically sound to me, but you might want to think about using a switch statement, as nitass showed above, if you start expanding it to include any more options for User-Agent. The or conditional forces iRules to effectively run multiple if comparisons, one for each or clause, and after a handful of those you'll start seeing switch perform more efficiently. Not to mention switch is way prettier to look at, and we all like pretty code, right? Right. Colin