Forum Discussion
Thieß_Rathjen_1
Nimbostratus
Apr 13, 2006matchclass and string tolower
I am trying to match parts of the URI against a list of strings.
My problem is, that i have to convert both into lower case before, because i do not know if the customers types in lower or upper cas...
Apr 13, 2006
Your problem likely lies in the fact that you are passing a TCL list (gt_brand) into a function that expects a string (string tolower). Odds are the "string tolower" call in your matchclass command is casting the list to the first string in that list.
Question: why are you adding mixed case to your class and then converting it to lower case in the iRule. Why not just have it lower case to start with and then just convert the uri to lower case. Something like this might work:
class gt_brand {
"brand1"
"brand2"
"brand3"
}
when HTTP_REQUEST {
set tmp_uri [string tolower [HTTP::uri]]
set my_uri [getfield $tmp_uri "/" 2]
if { [matchclass $::gt_brand starts_with $my_uri] } {
log local0. "tmp_uri is $tmp_uri , my_uri is $my_uri"
}
}
One problem that I can foresee is that you are using the class as the first part of the comparison and that way if the URI matches any of them you could possibly end up with a false match (ie. http://brand/ would match since "brand1" starts_with "brand").
Since I don't know your application very well, I'm taking a shot here, but I would either replace "starts_with" with "equals" or go with something more like this:
class gt_brand {
"/brand1/"
"/brand2/"
"/brand3/"
}
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::uri]] starts_with $::gt_brand] } {
log local0. "found match with uri [string tolower [HTTP::uri]]"
}
}
In this case we reduce the number of temporary variables and make the rule much simpler. But, this is assuming that "http://brand1" is not a valid application request and that it requires a trailing slash like "http://brand1/".
Hopefully this gives you enough ammo to get you going.
-Joe
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