Forum Discussion

6 Replies

  • Check out the wiki:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__cookie.html
  • Ok here is the problem.

     

     

    I have a virtual server configured using the default cookie persistent profile.

     

     

    This virtual server responds to a number of hostnames:

     

    www1.mydomain.com

     

    www2.mydomain.com

     

    www3.mydomain.com

     

     

    the virtual server points all requests to a single pool.

     

     

    so if a user go to www1.mydomain.com, the BigIP will add a cookie like this "BIGipServermy_pool=88888888.55555.4444" so next time this user sends a request it will be directed to the same node as before.

     

     

    the thing is, this cookie doesnt have a domain set, so if I redirect the user to www2.mydomain.com, the BIGipServermy_pool cookie wont be sent since www2.mydomain.com is different than www1.mydomain.com. The BigIP then will select a new node for this user and create a new cookie.

     

     

    I tried doing this:

     

     

    when HTTP_RESPONSE {

     

    HTTP::cookie domain BIGipServermy_pool mydomain.com

     

    }

     

     

    But I see it was completely ignored, the cookie is still set without a domain.

     

     

    I am aware I can use the universal persistence profile to do the persistence based on the JSESSIONID cookie created by my application, which has the domain set. But Im only willing to do that as a last resort, because it is possible (very hard) that two different nodes have sessions with the same JSESSIONID.

     

  • Take a look at this thread:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=28&view=topic&forumid=5&postid=4763

     

     

    There are several more threads regarding cookie domains that you can search for if this one doesn't help. Any issues that these threads don't address, please post back.
  • my mistake.

    this :

    
    when HTTP_RESPONSE {
      if { [HTTP::cookie exists "BIGipServermy_pool"] } {  
         If the cookie does exist, let's grab the contents.
        set old_cookie [HTTP::cookie BIGipServermy_pool]
        log local0.NOTICE "OLD: $old_cookie"
         Now we delete it, then re-insert it with the domain info we want added.
        HTTP::cookie remove BIGipServermy_pool
        HTTP::cookie insert name BIGipServermy_pool value $old_cookie domain mydomain.com
        set new_cookie_domain [HTTP::cookie domain BIGipServermy_pool]
        set new_cookie [HTTP::cookie BIGipServermy_pool]
        log local0.NOTICE "NEW: $new_cookie"
        log local0.NOTICE "NEW: $new_cookie_domain"
     }
    }

    works.

    thank you very much.
  • After some testing I noticed that the iRule above has a problem. If more than one cookie is set on the response, the extra set-cookies will be lost and only the BIGipServermy_pool set-cookie will be sent to the client.

    So I made the following iRule that removes and resinserts every cookie that was set on the response.

    
    when HTTP_RESPONSE {
       set cookies [HTTP::cookie names]
       look for a persistence cookie being set 
       if { $cookies contains "BIGipServer" } {
          rewrites all cookies being set
          foreach cookie_name $cookies {
             set cookie_value [HTTP::cookie $cookie_name]
             HTTP::cookie remove $cookie_name
             HTTP::cookie insert name $cookie_name value $cookie_value domain "mydomain.com" path "/"
          }
       }
    }

    This way no cookie is lost.