Forum Discussion

Tiago_Teixeira_'s avatar
Tiago_Teixeira_
Icon for Nimbostratus rankNimbostratus
Nov 29, 2017

Preserve old cookie expire Irule

Hi, I have an Irule to remove old cookie and insert a new cookie and value. The dev team change the aplication and insert the expire age in old cookie. How I preserve this atribute in new cookie? Follow my Irule:

 

when HTTP_RESPONSE { set cookies [HTTP::cookie names] look for a persistence cookie being set if { $cookies contains "JSESSIONID" } { 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 ".mysite.com.ar" path "/" } } }

 

Thanks!

 

1 Reply

  • Based on your iRule need to add the expire but needs to be an additional command.

    when HTTP_RESPONSE { 
        set cookies [HTTP::cookie names] 
        look for a persistence cookie being set
        if { $cookies contains "JSESSIONID" } {
            rewrites all cookies being
            set foreach cookie_name $cookies {
                set cookie_value [HTTP::cookie $cookie_name]
                set cookie_expire [HTTP::cookie expires $cookie_name]
                HTTP::cookie remove $cookie_name 
                HTTP::cookie insert name $cookie_name value $cookie_value domain ".mysite.com.ar" path "/" version 0
                HTTP::cookie expires $cookie_name $cookie_expire absolute
                
            }
        }
    }
    

    However your iRule is replacing each cookie with the same cookie name and value, you can simple update the domain and path instead of remove and replace, this should not change the expires value set by the backend server:

    when HTTP_RESPONSE { 
        set cookies [HTTP::cookie names] 
        look for a persistence cookie being set
        if { $cookies contains "JSESSIONID" } {
            rewrites all cookies being
            set foreach cookie_name $cookies {
                HTTP::cookie domain $cookie_name ".mysite.com.ar"
                HTTP::cookie path $cookie_name "/"
            }
        }
    }