Hello 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