Forum Discussion

amr_magdy_25051's avatar
amr_magdy_25051
Icon for Nimbostratus rankNimbostratus
Apr 16, 2017

Irule that select pool memeber based on client language in http header

I am trying to make an irule that forwards traffic to a specific pool or pool member based on client language used in http header

 

  • when HTTP_REQUEST { if { [HTTP::header "Accept-Language"] starts_with "en" } { pool test member 10.2.0.11 80 } }

     

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    try below

    when HTTP_REQUEST {
    
      if { [HTTP::header "Accepted-Language"] contains "en-us" }  {
         pool Pool_english
              }
               }
    
  • Suggest you try the following...

    when HTTP_REQUEST {
      switch -glob [HTTP::header "Accept-Language"] {
        en* { pool pool_app_english }
        jp* { pool pool_app_japanese }
        de* { pool pool_app_german }
        default { pool pool_app_english }
      }
    }
    

    The accept language header defined in RFC7231 takes the form of 2 letter abbreviation of language followed by additional information. The above iRule allows you to pick pools for specific languages and even set a default. You can choose not have a default and it will use the pool attached to the virtual server instead.

  • Hi,

    Accept-language is a list of all accept languages... if the first language is not in the list, check for the second one until you find one manage language...

    when HTTP_REQUEST {
        pool pool_app_english
        foreeach language [split [HTTP::header "Accept-Language"] ","]
            switch -glob $language {
              "en*" { pool pool_app_english; break}
              "jp*" { pool pool_app_japanese ; break}
              "de*" { pool pool_app_german ; break}
              default { }
            }
        }
    }