Forum Discussion

JCMATTOS_41723's avatar
JCMATTOS_41723
Icon for Nimbostratus rankNimbostratus
Jun 10, 2014

Cookie and URI irule not working?

We have some ltms with 10.2 that will need to match on a cookie and uri irule logic and doesn't seem to be working properly.

 

when HTTP_REQUEST { if { ([class match [HTTP::cookie "UserInfo"] contains companyX]) and ( not [string tolower [HTTP::uri]] contains "/serviceb/")} { pool SERVER1 } }

 

I noticed that the cookie logic works fine by itself, but when I add the "and" logic it doesn't work. I'm wondering if my configuration is correct?

 

6 Replies

  • Probably need to move brackets around like below.

     

    when HTTP_REQUEST { 
      if { ([class match [HTTP::cookie "UserInfo"] contains companyX]) and \ 
           not ([string tolower [HTTP::uri]] contains "/serviceb/")} { 
        pool SERVER1 
      }
    }
    

    Just a tip, when posting iRules. Select your code and then press Tab. It will format it nicely for you 🙂

     

  • Kevin,

     

    Thx for you response. Is the \ after the "and" a typo?

     

    when HTTP_REQUEST { if { ([class match [HTTP::cookie "UserInfo"] contains companyX]) and \ not ([string tolower [HTTP::uri]] contains "/serviceb/")} { pool SERVER1 } }

     

    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      Take the \ out of the iRule. I think Kevin meant that as an indicator that the statement was continued on the next line.
  • Is the \ after the "and" a typo?

    Another common use of backslash substitution is for line continuation: Continuing long commands on multiple lines. When a line ends with a backslash, the interpreter converts it and the newline following it and all whitespace at the beginning of the next line into a single space character, then evaluates the concatenated line as a single command:
    

    iRules Optimization 101 - 04 - Delimiters: Braces, Brackets, Quotes and more by Deb Allen

    https://devcentral.f5.com/articles/irules-optimization-101-04-delimiters-braces-brackets-quotes-and-more.U5iQMihhfIU
  • The \ is a continuation character. If you put the following line back on the same line you don't need it.

     

    iRules/TCL is a bit quirky though. Sometimes it likes it and sometimes.... if its throwing errors then remove it.

     

  • If any of the below posts have provided a solution to your issue, please indicate so by clicking the tick to the left of them. This gives feedback and recognition to the volunteers who responded to your issue :-)