Forum Discussion

lisiecki_54902's avatar
lisiecki_54902
Icon for Nimbostratus rankNimbostratus
Jul 01, 2017

switch on multiple domains

I have multiple domains and want to match behavior for URI, can I use an or for the host?

 

switch [string tolower[HTTP::host]]

{
 "www.foo.com" -
"www.foobar.com" {
 switch -glob [HTTP::uri] {
     "/foo*" {
      do something
    }
     }
}
}

 

3 Replies

  • The - (dash) is your logical OR in switch-condition. Unlike in if-condition, you cannot use or as a word. If I get it right, you're trying to improve readability of this code? Would merging the two parts into one help?

     

    switch -glob [string tolower [HTTP::host][HTTP::path]] {
      "www.foo.com/foo*" -
      "www.foobar.com/foo*" {
         do something
      }
    }
    

     

    • lisiecki_54902's avatar
      lisiecki_54902
      Icon for Nimbostratus rankNimbostratus

      Hello Hannes, Thank-you for your reply. Unfortunately no to the merge. I have multiple domains but domain-A and domain-B both share all the same uri entries ( which I will switch for different pools). In the top level switch I need to match domain-A or domain-B, then I need to add different logic for domain-c, domain-d etc. Will the dash work as an or operator when evaluating hosts?

       

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus

      "Will the dash work as an or operator when evaluating hosts?"

       

      Yes it will work