Forum Discussion

Bryce_Halkerst1's avatar
Bryce_Halkerst1
Icon for Nimbostratus rankNimbostratus
Apr 18, 2013

iRule Data Group with string and regex

All,

 

Need to replace http class with with irule data group. Images are pretty straight forward, just need a little help with the regex images that are created on the http class.

 

HTTP Class

 

profile httpclass apache_content_httpclass {

 

defaults from httpclass

 

pool apache

 

redirect none

 

paths

 

"/*.gif*"

 

"/*.pdf*"

 

"/*.txt*"

 

"/*.css*"

 

"/*.GIF*"

 

"/*.SWF*"

 

"/*.PDF*"

 

"/*.TXT*"

 

"/*.CSS*"

 

"/*.flv*"

 

"/*.FLV*"

 

"/*.png*"

 

"/*.PNG*"

 

"/*.ico*"

 

"/*.swf*"

 

"/*.js"

 

regex ".*\\.js[^p]+.*"

 

glob "/*.JS"

 

regex ".*\\.JS[^p]+.*"

 

glob "/*.jpg*"

 

"/*.JPG*"

 

"/*.JPEG*"

 

"/*.jpeg*"

 

regex "(?i)^(?!.*\\.jsp).*\\.html?.*$"

 

glob "/*.eot*"

 

"/*ttf*"

 

"/*.ogv"

 

"/*.mpv"

 

"/*.webm"

 

"/*.m4v"

 

"/*.mp4"

 

}

 

 

 

6 Replies

  • You can't use wildcards, regex's or glob patterns in a DG I'm afraid; everything is interpreted literally.

     

  • As Steve said, classes don't support regex-style searches, but you can use the contains operator, which is functionally equivalent to "*something*". So while you may have to add more specific content type identifiers, the good news is that you can consolidate all of the oddly-cased variations of the same types by using a [string tolower ] match context.
  • Ok, so I am planning on doing something like this.

     

     

    Irule Data Group (should {} contain the value?)

     

    ltm data-group internal /Common/images {

     

    records {

     

    .CSS { } Example .CSS {.CSS}

     

    .FLV { }

     

    .GIF { }

     

    .JPEG { }

     

    .JPG { }

     

    .PDF { }

     

    .PNG { }

     

    .SWF { }

     

    .TXT { }

     

    .bmp { }

     

    .css { }

     

    .flv { }

     

    .gif { }

     

    .ico { }

     

    .jpeg { }

     

    .jpg { }

     

    .js { }

     

    .m4v { }

     

    .mp4 { }

     

    .mpv { }

     

    .ogv { }

     

    .pdf { }

     

    .png { }

     

    .swf { }

     

    .ttf { }

     

    .txt { }

     

    .webm { }

     

    }

     

    type string

     

    }

     

     

    when HTTP_REQUEST {

     

    if {[class match -value -- [string tolower HTTP::uri] contains images] } {

     

    pool Apache_Pool_80

     

    if { ([HTTP::uri] contains "/*.gif*") || ([HTTP::uri] contains "/qas*") } {

     

    pool Weblogic_Pool

     

    if {[HTTP::uri] contains "/webservices*" } {

     

    pool Weblogic_Services_Pool

     

    if {[HTTP::uri] contains "/atgws" } {

     

    pool buybuybaby.com_services_80

     

    } else {

     

    pool Apache_Pool_80

     

    }

     

    }

     

    }

     

    }

     

    }

     

     

  • Something like that should work. Else you could use a switch statement to check the file types in the iRule itself.

    
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::path]] {
    "*.css" -
    "*.pdf" -
    "*.txt" -
    "*.flv" {
     Select the Apache pool for static filetypes
    pool Apache_Pool_80
    }
    "/webservices*" -
    "/qas*" {
    pool Weblogic_Services_Pool
    }
    default {
     Select a pool for non-matching filetypes
    pool some_default_pool
    }
    }
    }
    

    Another reply on its way.

    Aaron
  • Here's an updated version of your approach:

    
    when HTTP_REQUEST {
    if {[class match -- [string tolower [HTTP::path]] ends_with images] } {
    pool Apache_Pool_80
    } elseif { ([HTTP::path] ends_with ".gif") || ([HTTP::uri] ends_with "/qas") } {
    pool Weblogic_Pool
    } elseif {[HTTP::uri] starts_with "/webservices" } {
    pool Weblogic_Services_Pool
    } elseif {[HTTP::uri] contains "/atgws" } {
    pool buybuybaby.com_services_80
    } else {
    pool Apache_Pool_80
    }
    }
    

    Aaron
  • All,

     

    This was an issue with persistence not http classes. Issue resolved.

     

    Thanks,

     

    Bryce