Forum Discussion
IT
Nimbostratus
Jul 22, 2010Persistence problem after modifying Set-Cookie
Hi,
We use cookie persistence on a VS in front of some tomcat servers.
Our goal is to add the domain at the end of every cookie in an HTTP response (BIGIP cookie, JSESSIONID cookie...)
So we have developped our first iRule, here is the code :
when HTTP_REQUEST {
set host [HTTP::host]
}
when HTTP_RESPONSE {
if { [HTTP::header exists "Set-Cookie"] } {
extract main domain name
set domain $host
set domain_parts [split $domain "."]
set domain_parts_count [llength $domain_parts]
set reduced_domain_parts [lrange $domain_parts [expr $domain_parts_count - 3] [expr $domain_parts_count - 1]]
set new_domain "; domain="
foreach part $reduced_domain_parts {
append new_domain "."
append new_domain $part
}
get the cookies
set cookies [HTTP::header values "Set-Cookie"]
remove the old cookies
HTTP::header remove Set-Cookie
foreach cookie $cookies {
set new_cookie $cookie
add the domain at the end of each cookie
append new_cookie $new_domain
add the cookie to the response
HTTP::header insert Set-Cookie $new_cookie
}
}
}
On a test VS, this works just fine, the cookie is correctly modified, no problem.
But when we put this iRule on our production VS, our users experienced disconnections. analysing the http stream, we saw that each response contains a new Set-Cookie: BIGIPServeur=xxx that is different for the cookie in the request. we have even seen request with two BIGIPServeur cookies.
Does anyone have a clue why this happens?
Thanks a lot!
- hoolio
Cirrostratus
That's a lot of processing. I think you could use a couple of inbuilt commands to do this much easier:when HTTP_RESPONSE { Loop through each response cookie by name foreach aCookie [HTTP::cookie names] { Set the domain on the cookie to .example.com HTTP::cookie domain $aCookie ".example.com" } }
- IT
Nimbostratus
Thanks for the quick answer. - hoolio
Cirrostratus
Are you trying to set the domain on response cookies to the exact requested domain from the HTTP host header or just the base domain? You could parse the domain from the requested host header value using the domain command and then use that saved value in HTTP_RESPONSE to set them.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects