Forum Discussion
need to simplify the below iRule which contain multipal if else statements, is it possible to replace with switch
With regards to the HTTP_REQUEST event, I would think that the way you're doing it is more efficient the 'prettier' alternative (which could involve setting a variable and updating the pool selection after your switch completes), since it's not using variables, which add a little bit of overhead. Though this looks like it has more redundant code, only one of the if statements would be executed in any one request, so would wind up being a little bit more performant. In the SERVER_CONNECTED event, you could simplify your code with a switch -glob statement, though I don't know if it would give you any better performance. Here's an update to your code that may be helpful (not much really changed though)
when RULE_INIT {
set doSSL 0
}
when HTTP_REQUEST {
HTTP::header remove "Accept-Encoding"
switch [string tolower [HTTP::host]] {
"abc.xyz.com" {
if {([HTTP::path] eq "/")} {
HTTP::header replace Host "def.pqr.com"
HTTP::uri "/ssearch/mail/ssoForm.jsp"
}
pool pqr
}
"abcadmin.xyz.com" {
if {([HTTP::path] eq "/")} {
HTTP::header replace Host "def.pqr.com"
HTTP::uri "/abc/pqr/login.jsp"
}
pool pqr
set doSSL 1
}
"test.xyz.com" {
if {([HTTP::path] eq "/")} {
HTTP::header replace Host "any.any.com"
HTTP::uri "/company/"
}
pool any
set doSSL 1
}
}
}
when SERVER_CONNECTED {
log local0. "pool [LB::server pool]"
switch -glob [string tolower [LB:server pool]] {
"*pqr*" -
"*any*" {
SSL::enable serverside
log local0. "z"
}
}
} And I noticed (maybe this isn't the entire iRule, you set doSSL in the HTTP_REQUEST, but don't use it anywhere else. You could modify your SERVER_CONNECTED event to use that variable instead of checking the pool if you wanted. Like this:
when SERVER_CONNECTED {
log local0. "pool [LB::server pool]"
if { $doSSL } {
SSL::enable serverside
log local0. "z"
}
} Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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