Forum Discussion
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
- JP_42120
Nimbostratus
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? - What_Lies_Bene1
Cirrostratus
Almost, I just think you need to use switch -glob $path { as you are using a wildcard character. - JP_42120
Nimbostratus
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. - What_Lies_Bene1
Cirrostratus
Looks good. You're welcome.
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