Forum Discussion
DocSmooTH_23746
Nimbostratus
Apr 07, 2008regexp match HTTP::host to choose pool
I couldn't find anything in this forum searching for "regexp http::host" or "regexp matchclass" that fit my problem, but we did get the idea from one of Joe's blog posts.
We have a bunch of ...
hoolio
Cirrostratus
Apr 08, 2008Taking Joe's idea (Click here) of using catch to handle errors if the pool doesn't exist, you could try this:
when HTTP_REQUEST {
Get the string from the host header value up to the first period. Set the string to lower case.
set parsed_pool pool_[string tolower [getfield [HTTP::host] . 1]]
log local0. "[IP::client_addr]:[TCP::client_port]: \$parsed_pool: $parsed_pool"
Try to assign the parsed pool as the pool for this request. Use catch to handle the error if the pool doesn't exist.
if {[catch {pool $parsed_pool}]}{
There was an error in trying to use the pool parsed from the hostname, so use the default pool
pool default_pool
log local0. "[IP::client_addr]:[TCP::client_port]: \$parsed_pool didn't exist: $parsed_pool. Using default pool."
}
}
Or here's a shorter version which expects that there is a default pool assigned to the VIP:
when HTTP_REQUEST {
Try to assign the parsed pool as the pool for this request. Use catch to handle the error if the pool doesn't exist.
if {[catch {pool pool_[string tolower [getfield [HTTP::host] . 1]]}]}{
The pool parsed from the host header didn't exist. Do nothing as the default pool will be used.
log local0. "[IP::client_addr]:[TCP::client_port]: parsed pool didn't exist: pool_[string tolower [getfield [HTTP::host] . 1]]. Using default pool."
}
}
And here's one more version that validates that the parsed pool is actually allowed (defined in a list in the iRule). This would prevent a user from being able to arbitrarily make requests to any pool defined on the BIG-IP:
when RULE_INIT {
Define a list of the pool names that can be accessed through this iRule.
set ::allowed_pool_names [list \
web-dev \
web-tst \
web-stg \
]
}
when HTTP_REQUEST {
Get the string from the host header value up to the first period. Set the string to lower case.
set parsed_pool [string tolower [getfield [HTTP::host] . 1]]
Check that the parsed pool name is defined in the list.
if {[matchclass $parsed_pool equals $::allowed_pool_names]}{
Assign the parsed pool for this request.
pool pool_${parsed_pool}
log local0. "[IP::client_addr]:[TCP::client_port]: Using pool pool_${parsed_pool}"
}
}
Aaron
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