Forum Discussion

mikand_61525's avatar
mikand_61525
Icon for Nimbostratus rankNimbostratus
Feb 17, 2012

Replace (and remove) characters from URIs?

Im trying to setup an irule that will convert "\" into "/" and also remove redundant "/" (turning "//" into "/") for HTTP::uri.

 

 

What is the recommended way (performance wise) to do these two things in v10 and v11 nowadays?

 

 

I also wonder how I can efficiently search for a group of specific hexvalues?

 

 

I understand one can use:

 

 

if { [string match {*abc*} $uri] }

 

 

to search for "abc" withing a string but im not sure that the following will work:

 

 

if { [string match {\x00 || \x01} $uri }

 

 

or am I supposed to to make a large if-statement out of this or can datagroup list be used aswell?

 

  • in case not using data group.

    e.g.

    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set uri [HTTP::uri]
       set cvt_back_slash [string map {\\ /} $uri]
       set rm_double_slash [string map {// /} $cvt_back_slash]
    
       log local0. "$uri -> $rm_double_slash"
    }
    }
    
    [root@ve1023:Active] config  cat /var/log/ltm
    Feb 17 03:30:43 local/tmm info tmm[4822]: Rule myrule : /test1\/test2/test3//test4 -> /test1/test2/test3/test4
    
  • data group.

    e.g.

    [root@ve1023:Active] config  b class convert_list list
    class convert_list {
       {
          "//" { "/" }
          "\\\\" { "/" }
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set uri [HTTP::uri]
       foreach item [class get convert_list] {
          set uri [string map $item $uri]
       }
       log local0. "[HTTP::uri] -> $uri"
    }
    }
    
    [root@ve1023:Active] config  cat /var/log/ltm
    Feb 17 03:55:35 local/tmm info tmm[4822]: Rule myrule : /test1\/test2/test3//test4 -> /test1/test2/test3/test4
    
  • Thanks! :-)

     

     

    Are there any drawbacks of using data group similar to use global variable vs local variable?