I need help on writing iRule for selectively compressing as in the below. This is one of acceleration requirements from an liability insurance company for mobile T/F(migrating core insurance system for mobile users).
1) Compress all HTTP responses except for compressed contents such as images.
2) Selectively compress for url using “*.uif”.
a) If content-encoding of HTTP response is “gzip”, then no compression needed.
b) Compress all others.
My first answers:
Must set the Compression to “Selective” in the profile
rule selective_compress_enable {
when HTTP_REQUEST {
if { ([HTTP::uri] eq “*.uif”) and ([HTTP::header value Content-Encoding] eq “gzip”) } {
I think you’ll want to enable/disable compression in HTTP_RESPONSE based on the response content-type. Though I’m not sure it makes sense to try to compress all content from the pool that’s not already compressed. I think you’d want to try to limit compression to content-types which can be compressed like text.
Also, do you want to enable or disable response compression for *.uif file requests? It looks like UIF files might already be compressed ISO images.
As far as the HTTP profile setting, the COMPRESS::enable wiki page states the following:
Note that when using this command, you must set the HTTP profile setting Compression to Selective.
when HTTP_REQUEST {
Prevent response compression if request is for a uif filetype
switch -glob [HTTP::path] {
"*.uif" {
set compress 0
}
default {
set compress 1
}
}
}
when HTTP_RESPONSE {
Enable compression if request was not for a uif filetype,
the response isn't already compressed and
the response is text-based
if {$compress and [HTTP::header Content-Encoding] ne "gzip" and [HTTP::header Content-Type] contains "text"}{
COMPRESS::enable
}
}
I guess you could do this with a custom HTTP profile. The URI checks and content-types can be configured. If the pool members use compression, you could prevent this by setting the Request Header To Erase to ‘Accept-Encoding’. This would be simpler and more efficient than an iRule.
So it sounds like we would only need to enable IRule compression if we are trying to do complex logic compression, but if we are just compressing by the content types of static files we should just do it using HTTP Profiles at the Virtual Server Level. Aaron, when you say:
“If the pool members use compression, you could prevent this by setting the Request Header To Erase to ‘Accept-Encoding’”,
So it sounds like we would only need to enable IRule compression if we are trying to do complex logic compression, but if we are just compressing by the content types of static files we should just do it using HTTP Profiles at the Virtual Server Level.
Exactly.
“If the pool members use compression, you could prevent this by setting the Request Header To Erase to ‘Accept-Encoding’”
You can set the HTTP profile to remove the Accept-Encoding header from HTTP requests sent to the pool. This would indicate to the server that the client does not support compression of response payloads.
That’s it. If you remove the Accept-Encoding header via the HTTP profile it will be removed from all requests. If you want to do this by the requested file type, you’d need to use an iRule.