Forum Discussion
Short iRule rewrite for efficiency/readability
I have a short iRule that is simple to understand. Logically, the iRule works by checking the host header against two known values and modifies the Host: header if neither match. This is how it's currently written:
when HTTP_REQUEST {
if { not (( [string tolower [HTTP::host]] equals "myapp1.domain.com" ) or
( [string tolower [HTTP::host]] equals "myapp2.domain.com" )) } {
HTTP::header replace "Host" [HTTP::host]:9070
}
}
Intuitively it seems this iRule could be written more efficiently, or at least easier to read. Normally I'd do this comparison in a SWITCH statement, but I can't seem to get SWITCH to work with negation. I know that there isn't a lot of efficiency to gain here, but I was hoping someone could give me some ideas on how they would accomplish this same logic?
Don't know that you need to negate the match, just perform no action on matching "myapp1" or "myapp2" and use the default case to perform your replace.
Don't know that you need to negate the match, just perform no action on matching "myapp1" or "myapp2" and use the default case to perform your replace.
- smp_86112Cirrostratus
That never occurred to me. Were you thinking of something like this?
when HTTP_REQUEST { switch -- [string tolower [HTTP::host] { "myapp1.example.com" - "myapp2.example.com" { } default { HTTP::header replace "Host" [HTTP::host]:9070 } } }
- smp_86112CirrostratusI tried this and it worked perfectly, and it makes much more sense to read. Exactly what I was looking for. Don't understand why it didn't occur to me to write it this way, but thanks for the idea!!
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