Help with logic on header check irule

Hello All,

So i have an irule in which I need to check http header for mozilla then check the URI then LB appropriately. after this condition I have 2 other URI that are from a browser and need to be LB appropriately.

So If /aaa does not come from mozilla send to pool aaa, otherwise send to zzzz

/bbb and /ccc are browser based and need to go to the respective pools.

I know I have the default pool at the end but i need to somehow that with an else after the

“*/aaa*” { pool aaa }

{else}

pool zzz}

/bbb and /ccc are browser based and will contain mozilla in the header field

when HTTP_REQUEST {

if { not [string tolower [HTTP::header Accept]] contains “Mozilla” } {

switch -glob [HTTP::host][HTTP::uri] {

“*/aaa*” { pool aaa }

“*/bbb*” { pool bbb }

“*/ccc*” { pool ccc }

default {

pool zzz }

}

}

}

OK, so you seem to be saying that /aaa is a special treatment compared to /bbb and /ccc? in which case, I think you’re describing this:

when HTTP_REQUEST { 
   switch -glob [HTTP::uri] { 
      "/aaa*" { 
         if { not [string tolower [HTTP::header "User-Agent"]] contains "mozilla" } { 
            pool aaa 
         } else { 
            pool zzz 
         } 
      } 
      "/bbb*" { pool bbb } 
      "/ccc*" { pool ccc } 
   } 
}

Is that what you mean? You mention needing a default, yet your description doesn’t seem to want one at all. Can you clarify?

So a few things I’d point out…

1) You’re using [HTTP:host] and then completely ignoring it. Also introducing potential vagueness into the switch - your logic would match, host.com/ccc/aaa/blahblahblah as “/aaa”, which is surely not what you want.

2) You’re using the Accept header, when you surely mean the User-Agent header?

[EDIT: s/mozilla/Mozilla/ as per Hoolio’s comment below ]

Good points Chris. Also, if you’re setting the User-Agent header to lowercase make sure the string you’re comparing it with is lower case, like “mozilla”.

Aaron

@ Chris - Yes I need /aaa to be lb based on header field detection I will try your changes.

@ Aaron thanks as well

I am going to try this to see if I can get this to work.