Forum Discussion

edgranados_1975's avatar
edgranados_1975
Icon for Nimbostratus rankNimbostratus
Oct 17, 2017

Irule question about switch -glob $host

Hello

I'm confused of what this irule does. Could someone explain?

when HTTP_REQUEST { 
    set host [HTTP::header host] 
    switch -glob $host {
        "dc.bangkokair.com" {pool cp-2sg-as-t1-mingo-prod_pool_81xx  }
        "sws-pg.as.havail.sabre.com" {pool cp-2sg-as-t1-mingo-prod_pool_81xx  }
        default { 
            pool cp-2sg-as-t1-mingo-prod_pool_81xx  
        } 
    } 
  • Assuming that xx represent different numbers then you can best explain it as..

        when HTTP_REQUEST { 
        set host [HTTP::header host] 
        switch -glob $host {
    

    Take the host entry and use it as a switch statement target

       "dc.bangkokair.com" {pool cp-2sg-as-t1-mingo-prod_pool_81xx  }
        "sws-pg.as.havail.sabre.com" {pool cp-2sg-as-t1-mingo-prod_pool_81xx  }
        default { 
            pool cp-2sg-as-t1-mingo-prod_pool_81xx  
        } 
    

    Search for the following and provide the appropriate pool of servers...

    • Matched dc.bankokair.com select pool cp-2sg-as-t1-mingo-prod_pool_81xx.
    • Matched sws-pg.as.havail.sabre.com select pool cp-2sg-as-t1-mingo-prod_pool_81xx.
    • If no matches select pool cp-2sg-as-t1-mingo-prod_pool_81xx

    The switch -glob allows you to do simple pattern matching as follows...

    Ends with "*.bankokair.com"

    Starts with "www.*"

    Contains "*.bankokair.*"

    Note the periods (.) have no special meaning. They just represent that character.

    From a high level perspective, if they type in http(s)://dc.bangkokair.com/* the name is mapped to the IP address (or external NAT) of this virtual server. Same for http(s)://sws-pg.as.havail.sabre.com/* but it will accept any name given the default pool selection.