We’d like to change the expiration date of a Cookie when a client comes in with a certain Useragent-string.
Normally our users just get the default Cookie which expires after the session.
So I thought, nothing easier than that:
when HTTP_REQUEST {
if {([HTTP::header User-Agent] contains "LEO")} {
HTTP::cookie expires Cookiename_Test 18144000
}
}
But this doesn’t work. Actually it completely rejects the useragent. I tried different variations, by changing the Time-format, by using “persist” and all the attached options, but none did work.
Can someone tell me what is wrong with this iRule? I might just oversee something. Although the f5 isn’t complaining about any syntactical issues.
The cookie in the request only contains a name and value. The expiration property is set by the server (or LTM) in responses. If you want to modify the cookie’s expiration time, you’d need to check for the cookie in the response. You could do something like this:
when HTTP_REQUEST {
Check the User-Agent string
if { [string tolower [HTTP::header User-Agent]] contains "leo" } {
Set a variable to check the cookie in the response
set check_cookie 1
} else {
Set a variable to check the cookie in the response
set check_cookie 0
}
}
when HTTP_RESPONSE {
Check if cookie exists
if { $check_cookie && [HTTP::cookie exists "Cookiename_Test"]}{
Update cookie expiry time
HTTP::cookie expires Cookiename_Test 18144000
}
}
If that doesn’t work as you expect, try adding logging of the requests/user-agents/cookies in the request and response. You could also use a browser plugin like HttpFox for Firefox or Fiddler for IE to see which cookies are being set/received.
Is it a cookie being set by LTM or by the web application? If the latter, is it a web app behind the VIP this iRule is added to? The iRule would only take effect once it’s been added to the VIP and only affect the cookies being set after the iRule is added.
If the cookie has already been set with no expiry time, I’m not sure how you’d have to set a new cookie to expire if the previous time it was set without an expiry time. For telling the client to delete cookies the name, value and path must match the previously set cookie.
It is a cookie set by the LTM. It is not set explicitly without expiry time, but it is just a standard LTM Cookie which expires by closing the browser.
This is when I use the site with my browser. This LEOtrace is a Useragent given by a proxy which is in between.
The LEO-part comes very far at the end. Could that be a problem? Although I use “contains” in the iRule as you suggested. I also tried “leotrace” btw, but that didn’t work either.
OK, in the meanwhile I tried a different approach, as I am afraid, that this might be a bug and I can’t wait for that.
The issue is, that certain members in a pool need to get a Cookie with a longer expiry-date (I know, from the above, it seems to have nothing to do with this), so I tried the following iRule:
when HTTP_RESPONSE {
if { [HTTP::cookie exists "Cookie_Test"] and [HTTP::cookie value "1718485258.20480.0000"] } {
HTTP::cookie expires Cookie_Test 18144000
}
But this doesn’t work. There’s some logical error in it.
On the other hand I am afraid, that with this iRule I just will have the same problem, that the cookie doesn’t get updated.
What I really would like, is a way to just assign a modified cookie when a specific member gets used, but I am afraid, that this is not possible.
“Dec 2 15:38:28 tmm tmm[1649]: 01220001:3: TCL error: nurago - can’t use empty string as operand of “&&” while executing “if { [HTTP::cookie exists “Cookie_Test”] and [HTTP::cookie value “1768816906.20480.0000”] } { HTTP::cookie expires Cookie_Tes…””
This makes sense when I come with no cookie at all. So I added an “else” saying “use pool pool2”. But still the same error (also in the ltm-log). Using the trial_and_error method I tool out the ‘[HTTP::cookie exists "Cookie_Test] and’ to leave just one Testoperator, but then I get the following in the Logs:
“Dec 2 15:47:22 tmm tmm[1649]: 01220001:3: TCL error: nurago - expected boolean value but got “” while executing “if { [HTTP::cookie value “1768816906.20480.0000”] } { HTTP::cookie expires Cookie_Test 18144000 } else { use …””
Sorry, I should have noticed that before. I think this is what you’re trying to do:
[HTTP::cookie value “Cookie_Test”] eq “1718485258.20480.0000”
I don’t think you need to check if the cookie exists first, as HTTP::cookie value will return a null length string even if the cookie name doesn’t exist.
Unfortunately I cannot insert this iRule, because when I am saving it I get the error:
line 4: [parse error: PARSE syntax 206 {syntax error in expression "[HTTP::cookie exists Cookie_Test] && [IP::s...": extra tokens at end of expression}] [{[HTTP::cookie exists Cookie_Test] && [IP::server_addr]:[TCP::server_port] eq "10.1.110.105:80"}]