Forum Discussion
C_D_18583
Nimbostratus
Apr 22, 2008Cookie set by application server
How can I write a rule that can pick up the cookie that is set by the application server and have the ability to reset it.
Essentially the requirement is when a user logins in to the application the first time F5 routes to any node but the applications will set the cookie and that cookie will be persisted by F5.
However , if that node should go down we would like F5 to clear that cookie and go back to reselect another node and then the application will set another cookie.
The rules partially works ( clears the local cookie ( myCookie ) when the node is down ) but the APP_SESSION_COOKIE is not reset hence it continues to persisting to a node that is marked down:
Please advise
when RULE_INIT {
set ::myPool default_pool
set ::myPort 80
set ::myCookie APP_SESSION_COOKIE
}
when HTTP_REQUEST {
set myServer [findclass [substr [HTTP::cookie $::myCookie] 0 2] $::ip_list " "]
log local0. "The Cookie identifier is: [substr [HTTP::cookie $::myCookie] 0 2]"
if { $myServer ne "" } {
if { [LB::status pool $::myPool member $myServer $::myPort] ne "down" } {
pool $::myPool member $myServer $::myPort
log local0. "Server picked is: $myServer $::myPort"
}
else {
HTTP::cookie remove "$::myCookie"
pool $::myPool
log local0. "Selected server [IP::server_addr] is down, reloadbalancing."
}
}
else {
pool $::myPool
log local0. "No valid cookie/server pairing found, load balancing request to any server in $::myPool."
}
}
- hoolio
Cirrostratus
Can you enable logging and then post the log output when the rule doesn't work? If you're able to log the HTTP request and response headers, that would help too. - Nicolas_Menant
Employee
I guess the issue here is that you remove the cookie in the request but it is not cleared from the client's browser - Nicolas_Menant
Employee
you can use something like that:set cookie_expire "$::myCookie=;expires=-1" HTTP::respond 302 Location "http://[HTTP::host][HTTP::uri]" "Set-Cookie" $cookie_expire
- C_D_18583
Nimbostratus
Thanks for the response , I did try the above statement but it gave me the same error . Here are some logs: - C_D_18583
Nimbostratus
I tried the following command but I could not get the browser cookie to reset - hoolio
Cirrostratus
What do you see in the Set-Cookie header on the client when the 302 response is sent?if {[catch {IP::server_addr}] server_ip}{ There was an error running IP::server_addr, so don't try to log the value log local0. "No serverside connection" } else { No error. There was a serverside connection, so the value is saved in $server_IP log local0. "\$server_ip: $server_ip" }
- C_D_18583
Nimbostratus
Thanks for all you help. I resolved the problem. Actually the irule was working fine except for the log statement was causing some errors as you mentioned above. I removed the log statement. - Colin_Walker_12Historic F5 AccountNice to know the iRule was working. Thanks much for letting us know how this one turned out!
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