Forum Discussion

Julio_Navarro's avatar
Julio_Navarro
Icon for Cirrostratus rankCirrostratus
Jan 09, 2019

iRule Switch/If/Else | using cookie name

Hello!

Question 1

I am looking for a way to use the "switch" option (instead of an if/else condition) when a certain cookie name is present.

For example:

switch [HTTP::cookie name] {
  "CookieOne" {
     do something...
  }
  "CookieTWO" {
     do something else...
  }
  default {
     do something else else...
  }
}

.... [HTTP::cookie name] <- in singular (not names)

Question 1

In case I use an if/else statement, is it possible to "lowercase" the cookie name and query the condition?

For example:

if { [ string tolower [HTTP::cookie] exists "JSESSIONID" ] } {.......

Please advise

J

  • So you want to do a for loop on the list of cookies that the names gives you:

    set cookies [HTTP::cookie names]
     loop through each cookie by name in request
    foreach aCookie $cookies {
       do Stuff (tm) to $aCookie
       switch $aCookie... or whatever you want to do
    }
    

    You can do the string tolower on a cookie name, but note that in your example it would never match because it would have to be all lower "jsesssionid"

    Hope this points you in the right direction!

    --D