Forum Discussion
How can I get a persistance cookie when a pool member is selected by an iRule?
Here's a framework that may work for you.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/public2" } {
set the desired pool
set this_pool "local-pool"
send traffic to pool and specific member
pool $this_pool member 10.70.0.3 80
if persistence cookie doesn't exist, set a flag to create one
if { not ( [HTTP::cookie exists BIGipServer$this_pool] ) } {
set insertcookie [list $this_pool "10.70.0.3" "80"]
}
}
}
when HTTP_RESPONSE {
if { [info exists insertcookie] } {
encode the IP
scan [lindex $insertcookie 1] %d.%d.%d.%d a b c d
set ip1 [format %02x $a]
set ip2 [format %02x $b]
set ip3 [format %02x $c]
set ip4 [format %02x $d]
scan $ip4$ip3$ip2$ip1 %x ip
encode the port
scan [format %04x [lindex $insertcookie 2]] %2s%2s e f
scan $f$e %x port
insert the cookie
HTTP::cookie insert name BIGipServer[string map {"/Common/" ""} [lindex $insertcookie 0]] value "$ip.$port.0000"
HTTP::cookie path BIGipServer[string map {"/Common/" ""} [lindex $insertcookie 0]] "/"
unset the variable
unset insertcookie
}
}
Based on some logic in the HTTP_REQUEST event, I set a flat (insertcookie) that is picked up in the HTTP_RESPONSE event. Using the following documentation:
sol6917: Overview of BIG-IP persistence cookie encoding
the HTTP_RESPONSE event encodes a persistence cookie the same way the cookie persistence profile would do it so that it's natively picked up and used. You'll need to apply the basic cookie (insert) persistence profile to the VIP. Perhaps the most interesting thing about this method is that you don't have to make any provisions on the request side to persist to a given pool member. The cookie name and value allows it to happen automatically. That said, this method isn't really required. You could have just as easily created your own cookie (with any value) in the response event and handled its return in the request event.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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