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
Hi Markus,
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.
Aaron - mpfeifer_63884
Nimbostratus
Hi Hoolio.
Thank you very much. This seemed to be the right solution. But unfortunately it doesn't update the cookie if we have one already.
If I delete the cookie and access the page, the it works although.
Markus - hoolio
Cirrostratus
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.
Aaron - mpfeifer_63884
Nimbostratus
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. - mpfeifer_63884
Nimbostratus
I found out, that in the Apache-logs the useragent-string looks like this:
Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5; LEOtrace
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. - hoolio
Cirrostratus
Can you try logging the value of the User-Agent header for all requests and add logging after the check for a User-Agent string containing leotrace?
Aaron - mpfeifer_63884
Nimbostratus
Hi Aaron, as I am not able to do the logging as you asked me to do, I figured, that it also happens with any other User-Agent, for example "Galeon":
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.5) Gecko/20091023 Galeon/2.0.7 (Ubuntu 2.0.7-1ubuntu2)
This is the User-Agent string, but it only gets the Cookie with modified expiry when it has no Cookie.
While Firefox gets a normal Cookie.
So it is the update or the recognizing of the Cookie, which seems not to work with this iRule. - mpfeifer_63884
Nimbostratus
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. - hoolio
Cirrostratus
Do you see the cookie being set, but being set with no expiry time? If not, can you explain the details of the failure scenario?
Aaron - mpfeifer_63884
Nimbostratus
I get:
"!Connection interrupted
The document contains no data.
The network link was interrupted while negotiating a connection. Please try again."
:/
And no cookie of course.
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
