Forum Discussion

Mike_Pones_6391's avatar
Mike_Pones_6391
Icon for Nimbostratus rankNimbostratus
Sep 22, 2005

User Agent?

I have a customer that is asking if I can make a load balance decition based on the URL and the user agent. I am not familiar with the user agent, but it sounds like it must add something to the request that tells it what browser the client is using.

 

 

Has anyone heard of this? I am trying to get more info from the client and possably a sniffer trace.

 

 

Thanks in advance.

 

 

Mike

5 Replies

  • No need for a sniffer trace. The URI is available with the http_uri varaible and the user agent is just a HTTP header that you can query with the http_header command.

    A simple test for the URI could be something like this:

    if (http_uri starts_with "/dir1/dir2" ) {
      use pool pool1
    } else if (http_uri contains "somthing") {
      use pool pool2
    } else if (http_uri ends_with ".gif") {
      use pool pool3
    }

    As for User-Agents, the tricky part here is not finding the value, but distinguishing the browser since each version of each browser has a different User-Agent string.

    I found this site from Google that lists out every browser I ever heard of (and many more)

    http://www.zytrax.com/tech/web/browser_ids.htm

    Click here

    Here are the values I see from browsers on my machine:

    IE6: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)

    FireFox 1.0.7: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7

    And to check the User-Agent header you could do something like the following:

    if (http_header("User-Agent") contains "Opera") {
      use pool opera_pool
    } else if (http_header("User-Agent") contains "Firefox") {
      use pool firefox_pool
    } else if (http_header("User-Agent") contains "Safari") {
      use pool safari_pool
    } else if (http_header("User-Agent") contains "MSIE") {
      use pool internet_explorer_pool
    } else if (http_header("User-Agent") contains "Netscape") {
      use pool netscape_pool
    } else if (http_header("User-Agent") contains "Mozilla/5.0") {
      use pool mozilla_pool
    } else {
      use pool other_browser_pool
    }

    Of course, you can mix-and-match these all together to suit your needs.

    Oh, and if you want to debug your script, make sure you throw in a few log statements

    log local0.debug "Uri: " + http_uri
    log local0.debug "UserAgent: " + http_header("User-Agent")

    For more information on the builtin variables and functions, I would suggest you check out the BIG-IP product manual (available online at tech.f5.com).

    -Joe
  • Joe, you ROCK!!!

     

     

    Is "User-Agent" a feild in the http header? Meaning I can use the following check but change "Opera" to what over browser or text I am looking for?

     

     

    if (http_header("User-Agent") contains "Opera")

     

     

    Thanks a TON

     

     

    Mike
  • I have been looking in the manual, but where can I get a list of the "header-tag-string" options.

     

     

    Thanks again,

     

     

    Mike
  • Posted By mpones on 9/22/2005 12:08 PM

     

     

    I have been looking in the manual, but where can I get a list of the "header-tag-string" options.

     

     

    If you look in the "iRules" section of the BIG-IP Reference Guide, look for the table titled "Expressions" where you will find all the http_* commands and variables as well as the relational operators (starts_with, contains, etc).

     

     

    Is this what you were asking or were you looking for something different?

     

     

    -Joe
  • Martin_Machacek's avatar
    Martin_Machacek
    Historic F5 Account
    Actually Opera allows the user to choose what browser type it reports. It offers Opera, Mozilla 5.0 and MSIE 6.0 :-) In all cases, the User-Agent string contains Opera (either at the begining or at the end). So, you should check for Opera before Mozilla and MSIE because the User-Agent string may contain both of them (along with Opera) ... or use a regular expression to narrow down the match (but it is slower than simple string matches).