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

JP_42120's avatar
JP_42120
Icon for Nimbostratus rankNimbostratus
Oct 18, 2012

irule performance: combine multiple irules

Hi,

 

We have an several irules that we are trying simplify and combine for better performance.

 

first to block certain URI's

 

 

when HTTP_REQUEST {

 

switch [HTTP::uri] {

 

"/proxy/" -

 

"/content/xmlmovies/undefined" -

 

"/duas/" {

 

HTTP::respond 404 content "404 - file not found."}

 

}

 

 

To log request with certain content size

 

if { [HTTP::header Content-Length] >= 9000 } {

 

log local0. "[HTTP::header Content-Length] byte [HTTP::method] request from [IP::client_addr] for [HTTP::host][HTTP::uri]"

 

}

 

 

Redirect to certain URI's to HTTPs

 

switch -glob [string tolower [HTTP::path]] {

 

"/login*" {

 

if {[TCP::local_port] == 80} {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

"/app/login_user*" {

 

if {[TCP::local_port] == 80} {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

"/app/new*" {

 

if {[TCP::local_port] == 80} {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

"/app/associate_new*" {

 

if {[TCP::local_port] == 80} {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

"/account*" {

 

if {[TCP::local_port] == 80} {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

}

 

}

 

14 Replies

  • I found something from another post...

     

    The original if {..} used "startswith"...

     

    I guess for the below switch {...} to work a * is used in the string...

     

     

    when HTTP_REQUEST {

     

    set path [string tolower [HTTP::path]]

     

    switch $path {

     

    "/proxy/*" -

     

    "/content/xmlmovies/undefined*" -

     

    "/duas/*" {

     

    HTTP::respond 404 content "404 - file not found."

     

     

     

    Does this look okay?
  • Almost, I just think you need to use switch -glob $path { as you are using a wildcard character.
  • gotcha!

     

     

    so somthing like this?

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::path]] {

     

    "/proxy/*" -

     

    "/content/xmlmovies/undefined*" -

     

    "/duas/*" {

     

    HTTP::respond 404 content "404 - file not found."

     

     

    thanks.