Forum Discussion

33boston_223's avatar
33boston_223
Icon for Nimbostratus rankNimbostratus
Jan 15, 2009

Gzip compression levels

Hi - New to irules so I was hoping someone could help with what I need to aaccomplish.

 

 

We would like to apply a higher compression level to any .aspx requests. How would I go about doing this? Is there a way to create an iRule that would read the content being .aspx and apply this higher level of compression while keeping the compression level in the profile the same for all other traffic?

 

 

Thanks!

5 Replies

  • hi,

    you can use the COMPRESS::gzip command to specify the compression level: Click here

    so you could try something like this:

     
     when HTTP_REQUEST { 
        if {[HTTP::path] ends_with ".aspx"} { 
            COMPRESS::gzip level 5 
        } 
     } 
     

    I don't recommend to go to 9 since it will use more CPU for not so much more compression

  • Hi - Thank you for the quick response. I tried the rule you suggested and it returned some errors. I've been continuing to look and found this

     

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::header Content-Type] ends_with "*aspx"} {

     

    COMPRESS::gzip level 5

     

    }

     

    }

     

     

    Now I didn't receive any errors but will this do what I'm looking for? Thanks again!
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    yep, that looks like it will do the trick. Might need to use "contains" operator, you should be able to tell by looking @ the headers sent by the server.

     

     

    I thought errors might be because you were trying to call a serverside command (COMPRESS::*) in a clientside context (HTTP_REQUEST), but wiki page says it works in HTTP_REQUEST & shows an example.

     

     

    Were you getting the "not valid in current context error" or ...?

     

     

    /deb

     

  • Hi- This is what I was getting- line 3: [command is not valid in current event context (HTTP_REQUEST)] [COMPRESS::gzip level 5]

     

     

    I'm going to implement this today and see what happens. Thanks again for the help!
  • it is a strange error message since based on the WIKI you should be allow to use it within HTTP_REQUEST... maybe you are not authorized and can only do it in the response

    if this is the case you can do something like this:

     
     when CLIENT_ACCEPTED { 
        set increase_compress 0 
     } 
      when HTTP_REQUEST {  
         if {[HTTP::path] ends_with ".aspx"} {  
               set increase_compress 1 
          } else { 
              set increase_compress 0 
          } 
      }  
      
     when HTTP_RESPONSE { 
        if {$increase_compress equals "1"} { 
               COMPRESS::gzip level 5  
        } 
     }