Forum Discussion
mpfeifer_63884
Nimbostratus
Nov 30, 2009cookie expire
Hi.
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.
thx.
Markus
19 Replies
- hoolio
Cirrostratus
That sounds like a TCP reset being sent from the server side. Can you check the /var/log/ltm log file for any run time TCL errors?
Aaron - mpfeifer_63884
Nimbostratus
It says:
"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 ..."" - hoolio
Cirrostratus
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.
Aaron - mpfeifer_63884
Nimbostratus
Thank you Aaron. OK, this kind of works. But still is not my favourite way to handle the whole thing.
Isn't there a way to already set the Cookie at the first Request already instead of waiting for the response?
I tried a few options:when LB_SELECTED { if {[IP::addr [LB::server addr] equals 10.1.110.105] } { persist cookie insert Cookie_Test 18144000 } }
What I am trying to do here:
When the member 10.1.110.105 gets selected to direct the traffic to, then set Cookie with expirydate.
But it doesn't set the expiry-date of the cookie, instead they get the normal default session-cookie
A similar idea was the following:when HTTP_REQUEST { if { [LB::status pool preview99 member 10.1.110.105 80] eq "up" } { persist cookie insert Cookie_Test 18144000 } }
If the specified member in pool preview99 is up, give the special expiry cookie.
But this gives the Cookie with exprydate to all members in the pool and not only to 10.1.110.105
Probably because for the LB it is only important if that member is up, regardless if he is going to use it or not.
I must be overseeing something.
Does someone have an idea? - hoolio
Cirrostratus
I would have expected this rule to work for you:when LB_SELECTED { if {[IP::addr [LB::server addr] equals 10.1.110.105] } { persist cookie insert Cookie_Test 18144000 } }
I tried testing on 9.3.1 and 10.0.1, but couldn't set the cookie timeout from an iRule. You might try opening a case with F5 Support on this.
As a workaround, you could try something like this:when HTTP_RESPONSE { log local0. "[IP::client_addr]:[TCP::client_port]: Set-Cookie: [HTTP::header values Set-Cookie]" if {[HTTP::cookie exists $my_persist_cookie] && [IP::server_addr]:[TCP::server_port] eq "10.1.110.105:80"}{ HTTP::cookie expires $my_persist_cookie 86400 } log local0. "[IP::client_addr]:[TCP::client_port]: Set-Cookie: [HTTP::header values Set-Cookie]" }
Aaron - mpfeifer_63884
Nimbostratus
Hi Hoolio. Thank you very much.
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"}]
And I can't figure out what is wrong. - hoolio
Cirrostratus
Sorry, can you try this with the IP:port wrapped in double quotes:when HTTP_RESPONSE { log local0. "[IP::client_addr]:[TCP::client_port]: Set-Cookie: [HTTP::header values Set-Cookie]" if {[HTTP::cookie exists $my_persist_cookie] && "[IP::server_addr]:[TCP::server_port]" eq "10.1.110.105:80"}{ HTTP::cookie expires $my_persist_cookie 86400 } log local0. "[IP::client_addr]:[TCP::client_port]: Set-Cookie: [HTTP::header values Set-Cookie]" }
Thanks,
Aaron - mpfeifer_63884
Nimbostratus
Hi Aaron. This accepts the iRule in the GUI, but it doesn't update the cookie. Hm. - mpfeifer_63884
Nimbostratus
I meant: the cookie doesn't get updated.
It gets a cookie with the special expiration date, but at the second request, the expiration-date doesn't get updated.
And also if a normal Session-cookie (without expiration-date) exists, it doesn't update it with the new one.
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
