Forum Discussion

pponte's avatar
pponte
Icon for Altostratus rankAltostratus
Jun 12, 2017

Switch option always matches on default

Hello everybody. I have one question which probably for some people should be something simple, but I have spent a few days on a lab environment and studying a lot, with no succesfull results. I need to do a previous check to send a path which starts with /pf to a pool, but always goes to the default pool. The first or second part is working, but I can't make it work together.

This is the iRule:

when HTTP_REQUEST 
{
if {[string tolower [HTTP::uri]]  starts_with "/pf" } 
                    { 
                    HTTP::uri [string map {"/pf/" "/PF/"} [HTTP::uri]]
                    pool Pool_apache_lab
                    } 

  switch -glob [string tolower [HTTP::path]] {
     "default"      {            HTTP::respond 200 content {
                                                          Default switch 
                                                          }
                                }
}                   
}

Mandatory is not to touch "switch -global", but for the first match, I can use a "global", "if", "else if" or anything you suggest.

Thanks in advance.

  • I don't understand your problem. If you only have the default option in the switch, it always triggers that.

     

    Can you explain a little bit more the problem?

     

  • Hi,

    I think you want to include the first condition in the switch command:

    when HTTP_REQUEST {
        switch -glob -- [string tolower [HTTP::path]] {
            "/pf*" {
                HTTP::uri [string map {"/pf/" "/PF/"} [HTTP::uri]]
                pool Pool_apache_lab
            }
            "default" {
                HTTP::respond 200 content {Default switch}
            }
        }
    }