Forum Discussion
Hi, I've achieved a similar thing recently to delete APM cookies and restart session. I can confirm the only way to delete cookies on client side is forcing them to expire. Try to see if my code snippet helps you. Also, I'm only removing cookies for specific domain since that was what I needed for my environment, use browser tools to determine whether you need this or not.
when HTTP_REQUEST {
set refererfound 0
if {[string tolower [HTTP::header value Referer]] eq "<censored>"}{
set refererfound 1
HTTP::header replace Referer ""
set reqcookies [HTTP::cookie names]
foreach cookie $reqcookies {
HTTP::cookie remove $cookie
}
}
}
when HTTP_RESPONSE_RELEASE {
if {$refererfound eq 1}{
foreach acookie $reqcookies {
HTTP::header insert Set-Cookie "$acookie=deleted; domain=<censored>; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"
}
}
}
hey, I'm trying something similar, so if I want to do it for just 1 domain do I just replace your if condition to match the HTTP host? The domain is simple like example.com
if {[string tolower [HTTP::header value Referer]] eq "<censored>"}{ #replace with HTTP host instead of referer here? Will that work?
- CA_ValliMar 15, 2022MVP
Hello David, syntax-wise it will work; however consider that this will mean cookies will be dropped every time since iRule is executed at every request hit.
If you need "fresh" cookies to be generated and kept in next requests, you might want to consider injecting some cookie yourself, that will allow you to ignore the "cookie drop" on next requests.
I didn't need this in my scenario, since I was only concerned about a very specific HREF call.
Also, check the Set-Cookie instruction in response release event too, it might require tuning.
- David_MMar 16, 2022Cirrostratus
This is my post where i want to delete cookies based on domain name . .any thoughts??
- CA_ValliMar 16, 2022MVP
It's not clear to me what you're trying to achieve, if you just need to remove persistence cookie and always rely on pool LB selection method, there is "persist none" iRule instruction.
If you need to remove all cookies (why?) you can use my iRule, keep in mind this will delete persistence cookie as well. If you need to keep persist cookie, you can set it manually in the iRule with " persist cookie insert my_cookie_name "0d 00:00:00" " instruction and/or write some additional lines to save it & restore it after "cleanup cycle" is performed.