Forum Discussion
Mike_Pones_6391
Nimbostratus
Sep 22, 2005User 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 requ...
Sep 22, 2005
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.htmClick 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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects