Forum Discussion

eneR_159774's avatar
eneR_159774
Icon for Nimbostratus rankNimbostratus
Dec 04, 2014
Solved

Delete all Cookies if var x = true

Hello guys! I have a question regarding my extreme "huge" 😉 irule.

 

What is my goal?

 

  • Check if there are enough members in the "serverPool" >1
  • If not -> switch over to another "backupServerPool".
  • If the user got loadbalanced to the backupServerPool (and only then!) delete all (maybe a special one, not sure yet) cookies

irule:

 

when HTTP_REQUEST {
    set serverPool [LB::server pool]
    if { [active_members $serverPool] < 1 } {
    log local0. "blabla...." 

        if { [HTTP::cookie exists "secretcookiename"]}{          how can i check here for any cookie? 
        set deleteCookie "1"
        }

pool backupServerPool

    }
} 
when HTTP_RESPONSE {
    if {$deleteCookie == 1){
    log local0. "blabla...."
    HTTP::header remove Cookie   is this enough or do i have to name the cookies?
    unset deleteCookie
    }
}

2 Questions:

 

  1. Would this code work like desired?

     

  2. Is there another / better way to realize it?

     

thx in advance

 

  • To delete all cookies you need something like this:

       set cookieNames [HTTP::cookie names]
       foreach aCookie $cookieNames {
          HTTP::cookie remove $aCookie
       }
    

4 Replies

  • John_Alam_45640's avatar
    John_Alam_45640
    Historic F5 Account

    To delete all cookies you need something like this:

       set cookieNames [HTTP::cookie names]
       foreach aCookie $cookieNames {
          HTTP::cookie remove $aCookie
       }
    
    • eneR's avatar
      eneR
      Icon for Cirrostratus rankCirrostratus
      Okay that makes sense, thx. So if i want to delete just a single cookie the syntax would be: HTTP::cookie remove "cookiename"
    • John_Alam_45640's avatar
      John_Alam_45640
      Historic F5 Account
      Correct, HTTP::cookie remove "cookiename" removes one cookie by that name. https://clouddocs.f5.com/api/irules/HTTP__cookie.html
  • eneR's avatar
    eneR
    Icon for Cirrostratus rankCirrostratus
    when HTTP_REQUEST {
      set VSPool [LB::server pool]
        if { [active_members $VSPool] < 1 } {
        log local0. "blabla..."
    
            if { [HTTP::cookie exists "cookiename"]}{
            set deleteCookie "1"
            }
        pool backupPool
        }
    } 
    
    when HTTP_RESPONSE {
        if { $deleteCookie == 1}{
        log local0. "blabla.."
        HTTP::cookie remove "cookiename"
        unset deleteCookie
        }
    }
    

    Found some wrong braces by my own höhö.

    Now it should work.

    Another Question: What is better / faster -> to unset the deleteCookie var or to set it on "0" for example?! 😮