1

F5 BIG-IP 10.2.4

My iRule needs to exact-match on host and wild-card match on path.

when HTTP_REQUEST {
  switch [string tolower [HTTP::host]] {
    "internal.mycompany.com" {
      switch -glob [string tolower [HTTP::path]] {
          "/api1/*" {

Is this optimized as it is ? Would re-structuring as a single iRule provide further optimization ?

set $host [string tolower [HTTP::host]] 
set $path [string tolower [HTTP::path]]        
set $host-uri = "$host/$path"
when HTTP_REQUEST {
  switch -glob [$host-uri] {
    "internal.mycompany.com/api1/*" {
BaltoStar
  • 189
  • 2
  • 11

1 Answers1

0

It depends. How many domain names do you have on the VIP? If more than one, how many URIs under the domain name would you have ?

If it's going to be allot and you will be updating it quite frequently then I would suggest using a data group so you dont have to modify your iRule all the time. Otherwise it's 6 of one, half a dozen of another.

Something to the effect of -

when HTTP_REQUEST {
   set URL [string tolower [HTTP::host][HTTP::uri]]
   if {[class match $URL starts_with some_data_group]} {
      <some_action_based_on_DG_value> [class match -value $URL starts_with some_data_group]
   }
}

The value for the data group item could be a redirect URL, pool, persistence method, etc.

One other quick note; since your set statements are performing irule commands they need to be within the context of a valid event (i.e. [HTTP::host] must be inside "when HTTP_REQUEST").