Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Sep 20, 2011

how to merge these conditions to one :matches_regex

how to merge these conditions to one

 

if {$port == 443 and $uri matches_regex "^(/up)"} {

 

persist none

 

pool SRWD42-SLX

 

}

 

elseif {

 

$port == 443 and $uri matches_regex "^(/auto/bu)"} {

 

persist none

 

pool SRWD42-SLX

 

}

 

elseif {$port == 443 and $uri matches_regex "^/auto/Da"} {

 

persist none

 

pool SRWD42-SLX

 

}

 

 

and how to merge if it is start_with?

 

  • There is probably a more efficient way to do this, but:

    
    if { ($port == 443) and (($uri matches_regex "^(/up)") or ($uri matches_regex "^(/auto/bu)") or ($uri matches_regex "^/auto/Da")) }{
        persist none
        pool SRWD42-SLX
    }
    

    
    if { ($port == 443) and (($uri starts_with "/up") or ($uri starts_with "/auto/bu") or ($uri starts_with "/auto/Da")) }{
        persist none
        pool SRWD42-SLX
    }
    
  • I created two code blocks and shown both ways, but the interpreter squashed it...I guess you get the idea.
  • hmm,Brian

     

    I think it should be

     

     

    if { ($port == 443) and $uri matches_regex "^(/up|/auto/bu|/auto/Da)" }{

     

    persist none

     

    pool SRWD42-SLX

     

    }

     

     

    right?
  • I'd use a switch statement for this. It should be a lot more efficient than the regex checks.

    
    if {[TCP::local_port] == 443}{
    
       switch -glob -- [HTTP::uri] {
          "/up*" -
          "/auto/bu*" -
          "/auto/Da*" {
             persist none
             pool SRWD42-SLX 
          }
          default {
              Take some default action?
          }
       }
    }
    

    Aaron
  • Nice, so the first two conditions fall through to the third...much cleaner I think...