Forum Discussion

Brian_Gupta_115's avatar
Brian_Gupta_115
Icon for Nimbostratus rankNimbostratus
Jan 27, 2005

Need a sanity check on a URI parsing rule...

   
   when HTTP_REQUEST {      
       set my_uri [string tolower [HTTP::uri]]      
       if { $my_uri contains "/hr" or  $my_uri starts_with "hr" } {      
         pool hrmstest      
       } elseif { $my_uri contains "/selfservice" or $my_uri starts_with "selfservice" } {      
         pool hrmstest      
       } elseif { $my_uri contains "/fi" or  $my_uri starts_with "fi"  } {       
         pool fintest       
       } elseif { $my_uri contains "/fd" or  $my_uri starts_with "fd"  } {       
         pool fintest      
       } elseif { $my_uri contains "/ofi" or  $my_uri starts_with "ofi"  } {       
         pool fintest       
       } elseif { $my_uri contains "/cr" or  $my_uri starts_with "cr"  } {       
         pool crmtest       
       } else { pool fintest }     
     }     
   

I am going to use "hr" test as the example of what I am trying to accomplish.

For the following URLs I want to use pool hrmstest:

https://pstest2.timeinc.com/psp/SELFSERVICE/?cmd=login

https://pstest2.timeinc.com/selfservice

https://pstest2.timeinc.com/psp/SELFSERVICE/EMPLOYEE/HRMS/h/?tab=DEFAULT

https://pstest2.timeinc.com/hrtest

https://pstest2.timeinc.com/hr

https://pstest2.timeinc.com/psp/HR/?cmd=login

https://pstest2.timeinc.com/hrdmo88

https://pstest2.timeinc.com/HRIPC

https://pstest2.timeinc.com/HRUPG

https://pstest2.timeinc.com/HRIPC2

https://pstest2.timeinc.com/psp/hrdm88s1

https://pstest2.timeinc.com/HRTEST

https://pstest2.timeinc.com/HRDEV

https://pstest2.timeinc.com/HRRAC1

https://pstest2.timeinc.com/HRSNG

Will my rule accomplish this? And is there a more efficient way to accomplish this?

Finally I need to use cookie persistence. Can I just use a profile in combination with this rule or will I need to extend my rule to cover persistence?
  • bl0ndie_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    Brian using match class might simplifiy your rule. Here is an example.

     
     class hrmstest_uris {  
       "/psp/SELFSERVICE/?cmd=login" 
       "/selfservice" 
       "/psp/SELFSERVICE/EMPLOYEE/HRMS/h/?tab=DEFAULT" 
       "/hrtest" 
       "/hr" 
       "/psp/HR/?cmd=login" 
       "/hrdmo88" 
     }  
      
     when HTTP_REQUEST {    
        if { [matchclass [HTTP::uri] equals $::hrmstest_uris] } {  
           use pool hrmstest  
        }  
        else {     
           use pool fintest  
        }  
      } 
     

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    You may also use multiple classes to partition your pool matching.

    Eg, create several classes (aka "data groups" or "value lists").

       
     class hrmstest_uris {   
      "/hrtest"   
      "/hr"   
      "/psp/HR"   
     }   
     class crtest_uris {   
      "/cr"   
     }   
     

    Then in your rule have:

       
     when HTTP_REQUEST {   
        if { [matchclass [HTTP::uri] starts_with $::hrmstest_uris] } {   
           pool hrmstest   
        }   
        elseif { [matchclass [HTTP::uri] starts_with $::crtest_uris] } {   
           pool crtest   
        }   
        else {   
           pool fintest   
        }   
     }   
     

    You could also use a combination of matchclass tests with standard contains/starts_with tests.

    Also, the matchclass commmand can be used with the operators equals, contains, starts_with and ends_with.

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account

     

    Finally I need to use cookie persistence. Can I just use a profile in combination with this rule or will I need to extend my rule to cover persistence?

     

     

    Yes, you may simply add a cookie persistence profile. Your rule only selects the pool to use and does not affect persistence within that pool.
  • I setup the classes. For one of the pools I needed to use serverssl. I enabled serverssl on the pool and made this rule:

        
     when HTTP_REQUEST {   
       set my_uri [string tolower [HTTP::uri]]  
       set usessl 0  
       if { [matchclass $my_uri contains $::ps_hrms_uris] } {     
         pool hrmstest  
       } elseif { [matchclass $my_uri contains $::ps_fin_uris] } {   
         pool fintestssl  
         set usessl 1  
       } elseif { [matchclass $my_uri contains $::ps_crm_uris] } {  
         pool crmtest  
       } else {   
         pool portaltest  
       }  
     }  
        
     when SERVER_CONNECTED {   
       if { $usessl == 0 } {   
         SSL::disable   
       }   
     }  
     

    Please let me know if you know of a better way to do this.

    Thanks,

    Brian
  • Quick question regarding TCL Boolean. Is 0 or 1 = true?

     

    IE: Could I replace { $usessl == 0 } with { $usessl }

     

     

    If so which version is more effecient?

     

     

    Thanks,

     

    Brian
  • When TCL convers expressions to a boolean value (which is the same for every other language I know), zero is false and non-zero is true.

     

     

    To answer your question, you could never replace the first with the second because the two statements negate eachother. If usessl = 0, the first statement would be true since usessl equals 0, but the second would be false as the value is zero. If usessl = 1, the first statement would be false since usessl doesn't equal zero, and the second true.

     

     

    If you are talking about optimizations, my guess would be that the later is slightly faster as the interpreter doesn't need to do the first step of comparing the two values. Although, the improvment would probabaly be so miniscule that it wouldn't warrant worrying about. In this case, I would just worry about readability and maintenace of the rule. Just keep in mind that if you don't explicitly state an equals operation, anything non-zero will equate to true which may not be what you are expecting.

     

     

    -Joe