Forum Discussion
tkarni_92568
Apr 29, 2008Historic F5 Account
Cookie persistence with path attribute
Hi,
The need is to use persistence only for URLs under the "/login/" directory.
All other requests should be load balanced (OneConnect is enabled on the VS).
The chosen method is cookie.
I think the best way could have been to use "persist cookie insert" with a path attribue in the HTTP_REQUEST event to match "/login". But since there is no path attribute, I achieved the goal in a different way (see below).
But now the iRule works on the response as well and adds more work in the overall.
Is there a better way to achieve this, more efficient?
Thanks in advance!
Tom.
when HTTP_REQUEST
{
This is the cookie name used for persistence in the response
set persistence_cookie_name "bigippi"
Get the first 7 characters of the URI
set seven_chars_uri [string range [HTTP::uri] 0 6]
Check if the first 7 characters of the URI equal "/login"
if {[string tolower $seven_chars_uri] eq "/login/"}
{
There is a match so set a persistence cookie in the response
persist cookie insert $persistence_cookie_name
}
else
{
There is no match so use no persistence cookie
persist none
}
}
when HTTP_RESPONSE
{
Check if the resposne contains the persistence cookie
if {[HTTP::cookie exists $persistence_cookie_name]}
{
Set the persistence cookie path to the first 7 characters of the URI
HTTP::cookie path $persistence_cookie_name $seven_chars_uri
}
}2 Replies
- The_Bhattman
Nimbostratus
Did you take a look at these 2 links
Provides persistence on the JSessionID value found in either the URI or a cookie.
Click here
URI Session ID based persistence issue
Click here
Maybe it give you ideas of how to write more efficient - tkarni_92568Historic F5 AccountThanks Colin.
I considered your suggestion, but anyway I have to use the string range since I want to set the cookie path with the same case variant as appears in the URI.
I compare the first 7 characters to "/login" in lower case, but it may be that the path is "/Login/". In that case, I have to get the first 7 characters from the URI and use them as the cookie path.
So I *have* to use string range...
Now the question is:
If I already have the 7 characters string, is it still "cheaper" to use the "starts_with" than the "eq"?
Is it the same cost to use the "starts_with" on the [HTTP::uri] as on the variable I created "$seven_chars_uri"?
Thanks,
Tom.
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
