Forum Discussion
gzip filter
I want to filter gzip requests.if http requests have gzip ,I want to login server.Otherwise don't login .
I write an irule like down but it isn't working.what changes I have to do?
when HTTP_REQUEST {
if { ([HTTP::header "Accept-Encoding"] contains "gzip") or ([HTTP::header "Accept-Encoding"] contains "deflate") } {
pool Test_pool
log local0. "has been route [HTTP::header "Accept-Encoding"]: "
}
else {
HTTP::respond 500 Location "PLEASE SENT GZİP REQUEST"
log local0. "has not been route [HTTP::header "Accept-Encoding"]: "
}
}
10 Replies
- What_Lies_Bene1
Cirrostratus
You just need to take the quotation marks off the header name, other than that the iRule is good - but I've tidied it a bit further for you;when HTTP_REQUEST { if { ([string tolower [HTTP::header Accept-Encoding] contains "gzip"]) or ([string tolower [HTTP::header Accept-Encoding] contains "deflate"]) } { pool Test_pool log local0. "Compression enabled request has been routed [HTTP::header "Accept-Encoding"]" return } else { HTTP::respond 500 Content "PLEASE SEND A GZIP ENABLED REQUEST" noserver Content-Type "text/html" Connection "Close" log local0. "Non-Compression enabled request has NOT been routed [HTTP::header "Accept-Encoding"]: " } } - sukru_isik_8872
Nimbostratus
thank you steve,
I checked this irule with using soapUI program but all requests(gzip,none gzip) passed serverside. is there any way to control that irule is true or false? - What_Lies_Bene1
Cirrostratus
OK, sorry to suggest you haven't but you've applied the rule to the relevant Virtual Server yes? - sukru_isik_8872
Nimbostratus
of course I applied rule to the relevant virtual server. is there any extra mark place in virtual server you have known? - What_Lies_Bene1
Cirrostratus
Had to check =] Are you getting messages in the log at all?
What is the default Pool assigned to the VS, is it something other than Test_pool? - What_Lies_Bene1
Cirrostratus
More brackets around the if might also help;when HTTP_REQUEST { if { (([string tolower [HTTP::header Accept-Encoding] contains "gzip"]) or ([string tolower [HTTP::header Accept-Encoding] contains "deflate"])) } { pool Test_pool log local0. "Compression enabled, request has been routed [HTTP::header "Accept-Encoding"]" return } else { HTTP::respond 500 Content "PLEASE SEND A GZIP ENABLED REQUEST" noserver Content-Type "text/html" Connection "Close" log local0. "Compression disabled, request has NOT been routed [HTTP::header "Accept-Encoding"]: " } } - sukru_isik_8872
Nimbostratus
thank you for your help,Steve;
Now,it is working - What_Lies_Bene1
Cirrostratus
Great news, you're welcome. - hoolio
Cirrostratus
Hi Steve,
Nice example. You had the closing square brace for the string tolower command after the string you were checking. Here is an updated example and one showing how to use switch as well:when HTTP_REQUEST { if { [string tolower [HTTP::header Accept-Encoding]] contains "gzip" or [string tolower [HTTP::header Accept-Encoding]] contains "deflate" } { pool Test_pool log local0. "Compression enabled, request has been routed [HTTP::header "Accept-Encoding"]" } else { HTTP::respond 500 Content "PLEASE SEND A GZIP ENABLED REQUEST" noserver Content-Type "text/html" Connection "Close" log local0. "Compression disabled, request has NOT been routed [HTTP::header "Accept-Encoding"]: " } } or using switch: when HTTP_REQUEST { switch -glob [string tolower [HTTP::header Accept-Encoding]] { "*gzip*" - "*deflate*" { pool Test_pool log local0. "Compression enabled, request has been routed [HTTP::header "Accept-Encoding"]" } default { HTTP::respond 500 Content "PLEASE SEND A GZIP ENABLED REQUEST" noserver Content-Type "text/html" Connection "Close" log local0. "Compression disabled, request has NOT been routed [HTTP::header "Accept-Encoding"]: " } } }
Aaron - What_Lies_Bene1
Cirrostratus
Doh! Thanks =]
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
