For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Paedrig_69869's avatar
Paedrig_69869
Icon for Nimbostratus rankNimbostratus
Sep 20, 2016

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

  • 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)