Forum Discussion
Ian_J_37801
Nimbostratus
Feb 25, 2008Cookie persistence
Hi,
I am using cookie persistence to load balance some web servers. So far so good!
What happens though is the BigIP adds the cookie to the end of the cookie list as shown below: ...
hoolio
Cirrostratus
Feb 25, 2008Hello Ian,
I was thinking that you'd need to use an array, but that assumed that you could delete one header at a time. The HTTP::header remove command deletes all headers of that name though. So I used a list instead.
Can you give this a shot?
when RULE_INIT {
Set the name of the cookie to re-order the Set-Cookie headers for
set ::bigip_persist_cookie_name "BIGipServerDSA_WWW_3.32.1.2"
set ::bigip_persist_cookie_name "lastcookie"
Log debug messages (to /var/log/ltm)? 0=no, 1=yes.
set ::set_cookie_reorder_debug 1
}
when HTTP_RESPONSE {
Check if the response contains the BIG-IP persistence cookie
if {[HTTP::cookie exists $::bigip_persist_cookie_name]}{
if {$::set_cookie_reorder_debug}{log local0. "Found persist cookie. Re-ordering Set-Cookie headers"}
Save the Set-Cookie header values to a list
set set_cookie_values [HTTP::header values Set-Cookie]
if {$::set_cookie_reorder_debug}{log local0. "Values: $set_cookie_values"}
Remove the headers
HTTP::header remove Set-Cookie
Get the list index of the BIG-IP cookie's Set-Cookie header
set bigip_cookie_index [lsearch -glob $set_cookie_values ${::bigip_persist_cookie_name}*]
if {$::set_cookie_reorder_debug}{log local0. "BIG-IP cookie index: $bigip_cookie_index"}
Add back the BIG-IP cookie set-Cookie header first
HTTP::header insert Set-Cookie [lindex [lrange $set_cookie_values $bigip_cookie_index [expr $bigip_cookie_index + 1]] 0]
if {$::set_cookie_reorder_debug}{log local0. "Inserted BIG-IP cookie: [lindex [lrange $set_cookie_values $bigip_cookie_index [expr $bigip_cookie_index + 1]] 0]"}
Add back all Set-Cookie values except the BIG-IP cookie
for {set i 0} {$i < [llength $set_cookie_values]}{incr i}{
Check that this isn't the BIG-IP cookie Set-Cookie value
if {$i != $bigip_cookie_index}{
Insert the header
HTTP::header insert Set-Cookie [lindex [lrange $set_cookie_values $i [expr $i + 1]] 0]
if {$::set_cookie_reorder_debug}{log local0. "Inserting: [lindex [lrange $set_cookie_values $i [expr $i + 1]] 0]"}
}
}
Clear the list of saved headers
unset set_cookie_values
}
}
Aaron
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