Forum Discussion

Neil_66348's avatar
Neil_66348
Icon for Nimbostratus rankNimbostratus
Dec 14, 2012

Singular Cookie Insert

Hi Guys ,

 

A really easy one i'm sure for someone with good iRules knowledge.

 

We have a cookie rule which performs a simple insert for a HTTP Cookie

 

when HTTP_RESPONSE {

 

HTTP::cookie insert name Zend value 1

 

}

 

The above works well , however it inserts multiple cookies for each of the HTTP_Response.

 

Any ideas on how to tweak to make the iRule so that it , checks if the session cookie exists , if not it inserts .

 

Thanks

 

Neil

 

 

9 Replies

  • This should do it;

    
    when HTTP_RESPONSE {
     if { [HTTP::cookie exists "Zend"] } {
      Do nothing
      return }
     else {
      HTTP::cookie insert name Zend value 1 }
    }
    
  • Hi Steve ,

     

     

    Ahh yes it does remove some of them .

     

    However we end up with a "Zend" cookie , per path on the domain.

     

    So the domain is eg www.site.com , for each path

     

    / cookie

     

    /content cookie

     

    /assets cookie

     

    /content/en cookie

     

    /content/images cookie

     

    ....and so on for each element of the primary URI

     

     

    I guess it could because the HTTP response is per path , where almost want it as per virtual server for the client connection....no idea on that though...

     

     

    Thanks

     

    Neil

     

     

     

     

  • OK, so here's what I was thinking, if we insert the cookie we'll set a variable and then, if it's set we won't insert the cookie again;

    
    when HTTP_RESPONSE {
     if { [HTTP::cookie exists "Zend"] } {
      Do nothing
      return }
     elseif { $cookiecount equals 1 } {
      Do nothing
      return }
     else {
      HTTP::cookie insert name Zend value 1 
      set cookiecount 1 }
    }
    
  • Hi Steve ,

     

     

    Made one change on bracket , to get it save.

     

    when HTTP_RESPONSE {

     

    if { [HTTP::cookie exists "Zend"] }{

     

    Do nothing

     

    return }

     

    elseif { $cookiecount equals 1 } {

     

    Do nothing

     

    return }

     

    else {

     

    HTTP::cookie insert name BIGDC value 1

     

    set cookiecount 1 }

     

    }

     

     

    What odd , all appeared well with Google Chrome , but it broke the page with IE 9 and 10.

     

    LTM also logs :

     

    TCL error: /Jet2Reservations/AddCookie3 - can't read "cookiecount": no such variable while executing "if { [HTTP::cookie exists "Zend"] }{ Do nothing return } elseif { $cookiecount equals 1 } { Do nothing return } else { HTTP::cookie i..."

     

    I can get is means we need to set a variable....any help really appreciated....

     

     

    Thanks

     

     

    Neil
  • Hmmm, perhaps this will fix the issue;

    
    when HTTP_REQUEST {
      set cookiecount
    }
    when HTTP_RESPONSE {
     if { [HTTP::cookie exists "Zend"] } {
      Do nothing
      return }
     elseif { $cookiecount equals 1 } {
      Do nothing
      return }
     else {
      HTTP::cookie insert name Zend value 1 
      set cookiecount 1 }
    }
    
  • I can't find much documentation on set. It's possible we could set it (without specifying a value) in the HTTP_RESPONSE event but I'm worried that might clear it's value if it's been set to 1 already. Perhaps someone else can clarify?
  • Hi Guys ,

     

     

    Receive an error of :

     

    TCL error: /AddCookie4 - can't read "cookiecount": no such variable while executing "set cookiecount"

     

     

    Anyone have any further on how to set a cookie just the once... similar to a persistence cookie but used for LTM for any load balancing mechanism...

     

     

    Thanks

     

     

    Neil
  • I did post back earlier but it seems to have been lost. Try this (without the REQUEST event bit) - it might improve things but I'm not sure it'll remove the error entirely;

    
    when HTTP_RESPONSE {
     if { [HTTP::cookie exists "Zend"] } {
      set cookiecount 1
      return }
     elseif { $cookiecount equals 1 } {
      Do nothing
      return }
     else {
      HTTP::cookie insert name Zend value 1 
      set cookiecount 1 }
    }