Forum Discussion
iRule to process URI and Header data groups
Hi All,
I am trying to create an iRule that will match certain URIs against a data-group to decide which pool to send it to and then if no matching URI inspect the header and check against another data-group.
I am trying to make it dynamic enough to be able to be reused in multiple environments and may have to change from using [HTTP::path] to include the VIP port number as there may be multiple virtuals on the same IP/hostname for streams matching on the same path but sent to a different pool.
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::path]] starts_with dg_uri_pool_redirect] } {
pool [class lookup [HTTP::path] dg_uri_pool_redirect] }
elseif { [HTTP::header exists remote.contenttype] and [HTTP::header remote.contenttype] equals dg_header_pool_redirect } {
pool [class lookup [HTTP::header remote.contenttype] dg_header_pool_redirect]
}
}
1 Reply
- Michael_Jenkins
Cirrostratus
Apart from adding the hostname and path in your datagroup, you could use other datagroups to handle that... Untested, but perhaps something similar to this:
when HTTP_REQUEST { set hostLower [string tolower [HTTP::host]] set pathLower [string tolower [HTTP::path]] Use a datagroup matched on the host name that will give you the name of another datagroup to use to look up the pool redirect if { [class match $hostLower starts_with dg_host_dg_lookup] } { set dgName [class match -value $hostLower starts_with dg_host_dg_lookup] Now check the correct datagroup for the path if { [class match $pathLower starts_with $dgName] } { pool [class lookup $pathLower $dgName] return } If that didn't work, check for the header value if { [HTTP::header exists remote.contenttype] && [HTTP::header remote.contenttype] equals dg_header_pool_redirect } { pool [class lookup [HTTP::header remote.contenttype] dg_header_pool_redirect] return } } }You'd need to add additional data-groups for each host (which includes the hostname:port)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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