Forum Discussion

Neo_Moon_65417's avatar
Neo_Moon_65417
Historic F5 Account
Jun 21, 2011

Sectively compression for url using “*.uif”.

Hi all,

 

 

 

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") } {

 

log local0. "compression_rule_disable : *.uif & gzip"

 

COMPRESS::disable

 

}

 

else {

 

COMPRESS::enable

 

}

 

}

 

}

 

 

 

I am very new to iRule and I'd like to have help on this.

 

 

 

Thanks in advance,

 

 

 

Neo

 

7 Replies

  • Hi Neo,

    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:

    http://devcentral.f5.com/wiki/default.aspx/iRules/COMPRESS__enable.html

    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
       }
    }
    

    Aaron

  • Hello Aaron,

     

    Why not just add a list of content types to the http profile when enabling compression?

     

     

    So what's the different between HTTP profile compression vs. IRules compression?

     

    If there is a difference, when would it make more sense to use one method over the other?

     

     

    Thoughts?

     

     

    Regards,

     

    TRX

     

  • 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.

     

     

    Aaron
  • 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'",

     

     

    ... can you elaborate on what you mean by it?

     

     

    Regards,

     

    TRX
  • 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.

     

     

    Aaron
  • So you mean if one does NOT want to compress an certain type of file, then just remove the "Accept-Encoding" header from the http request. I like it. :)

     

     

    Thanks.

     

     

    Regards,

     

    TRX
  • 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.

     

     

    Aaron