Forum Discussion

N__197982's avatar
N__197982
Icon for Nimbostratus rankNimbostratus
Jan 13, 2016

iRule to detect the client browser the request is coming from.

Folks, I am looking for some iRule which will detect the kind of browser the request is coming from and then write some rules to handle this requests. I want to identify if the request is coming from a iPhone(any browser) or a normal desktop/laptop/other server(any browser).

 

Thanks, N.

 

2 Replies

  • Hi N.,

    in the past I've used the snippet below to perform those kind of checks...

     

    switch -glob -- [HTTP::header value "User-Agent"] "*iPhone*" - "*iPad*" - "*iPod*" - "*Opera M*" - "*Android*" - "*IEMobile*" - "*BlackBerry*" - "*Kindle*" {
    
         Mobile Client
    
    } "Mozilla*" - "Opera*" {
    
         Browser
    
    } default {
    
         Unknown Client
    
    }
    

     

    Cheers, Kai

  • Hi N.,

    the [switch -glob -- string1 string2 { action } ] command in the provided example is comparable with the [if { [HTTP::header value "User-Agent"] contains XYZ } then { action }] syntax. But its a little more elegant in this specific case...

    The final integration into an iRules would look like that:

     

    when HTTP_REQUEST {
        switch -glob -- [HTTP::header value "User-Agent"] "*iPhone*" - "*iPad*" - "*iPod*" - "*Opera M*" - "*Android*" - "*IEMobile*" - "*BlackBerry*" - "*Kindle*" {
    
             Mobile Client
            
             Place your additional code here
    
        } "Mozilla*" - "Opera*" {
    
             Browser
            
             Place your additional code here
    
        } default {
    
             Unknown Client
            
             Place your additional code here
    
        }
    }
    

     

    Cheers, Kai