Forum Discussion

Thieß_Rathjen_1's avatar
Thieß_Rathjen_1
Icon for Nimbostratus rankNimbostratus
Apr 13, 2006

matchclass 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 case.

Following rule does not 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 [string tolower $::gt_brand] starts_with $my_uri] } { 
    log local0. "tmp_uri is $tmp_uri , my_uri is $my_uri"
  }
}

if i remove the "string tolower"-statement in the matchclass line it works theoreticly, but i have the problem mentioned above.

Any proposals?

2 Replies

  • 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

  • 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.

     

    The class is a generated list of brandnames and i do not really know which cases are used.

     

     

    To simplify my problem i have shortened the rule. Before i try to match the uri against my class, i verify the domain.

     

     

    What i really try to do is if url is like http://www.domain.com/brand1 than redirect to http://domain.com/some_folder/brand1

     

     

    Thanks for the hint to replace "starts_with" with "equals". I will do that.

     

     

    If there is no way to lower a TCL list, i have to ensure, that my class will be in lower case.

     

     

    Thank you for the answer.

     

     

    --

     

    Thiess