Forum Discussion

cerpika_14370's avatar
cerpika_14370
Icon for Nimbostratus rankNimbostratus
Aug 12, 2010

iRule to send a cookie with every HTTP request

Cookie persistence in v10.2 will only send a cookie back to the client with the first http request/response of the connection. Subsequent requests/responses will not get a cookie sent back. This is a problem for us in our custom app.

 

 

I wrote an iRule

 

 

when HTTP_REQUEST {

 

set persistence cookie insert }

 

 

But that does not seem to be sending a cookie back with every HTTP response in the connection like I need. Does anyone know how I can do this?

 

 

TIA
  • Someone correct me if I am wrong here, but the cookie once it is sent to the client exists on their box until the timeout value has passed or it is manually deleted. So once one is set it lasts until the timeout value has gone passed. This generally only happens when the connection is idle though. If any info is passed and the cookie is used the time out value is generally reset back to the max time out value and the countdown starts over. If a cookie must be present but needs to be new each time, then the only thing I can think of is to change the cookies timeout value to 0 (not sure what this would do, probably just disable your persistence) or you could try to delete the existing cookie that you just set, every time you see it come in with an HTTP request.
    
     when HTTP_REQUEST { 
     priority 100 
      Check to see if the cookie exist in the request
     if { [HTTP::cookie exists "insert-cookie-name"] } { 
     Delete the cookie 
     HTTP::cookie remove "insert-cookie-name"  
     } 
     when HTTP_REQUEST { 
     priority 200 
     set persistence cookie insert "insert-cookie-name" } 
     } 
     } 
  • Sorry had to post this in two separate posts...

    If you want to just set the timeout value of your cookie to zero, then something like this should work (not sure of the 10.2 syntax):

     
     when HTTP_REQUEST { 
     set persistence cookie insert "insert-cookie-name" "0d 00:00:00" } 

    Just wondering, but could you fill me in on why the cookie needs to be sent to the client every time? Just curious about the application that you are using and why it works like that. Hope one of those helps.