Forum Discussion
Hank_Stallings
Nimbostratus
Jul 29, 2013Set Manual Cookie Peristence
I’m trying to implement an iRule from wiki article at:
https://devcentral.f5.com/wiki/irul...tence.ashx
I am pretty new at iRules and I’m missing something, so I apologize in advance for my...
Kevin_Stewart
Employee
Jul 29, 2013Updated for v10/11 with minor changes:
when RULE_INIT {
set static::cookie_name "my_node_forced"
}
when HTTP_REQUEST {
Get node id from URL ending in ?node=server1, ?node=server2, etc.
set node_forced [findstr [HTTP::query] "node=" 5]
Or from previous cookie
set has_cookie [HTTP::cookie exists $static::cookie_name]
If node_forced (from query) isn't there but cookie exists - set node_forced = cookie value
if { $node_forced eq "" and $has_cookie } {
set node_forced [HTTP::cookie value $static::cookie_name]
}
If node_forced (from query) is there but cookie is not - set cookie flag
if { $node_forced ne "" and !$has_cookie } {
set do_cookie 1
}
Map node id to IP and port found in a class
if { $node_forced ne "" } {
set node_data [class match -value $node_forced equals my_forced_nodes]
if { $node_data ne "" } {
set node_ip [getfield $node_data " " 1]
set node_port [getfield $node_data " " 2]
pool local-pool member $node_ip $node_port
}
}
}
when HTTP_RESPONSE {
if { [info exists do_cookie] } {
unset do_cookie
Add a cookie to continue forcing node assignment
HTTP::cookie insert name $static::cookie_name value $node_forced path "/"
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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