Forum Discussion

sukru_isik_8872's avatar
sukru_isik_8872
Icon for Nimbostratus rankNimbostratus
Nov 22, 2012

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

  • 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"]: "
    }
    }
    
  • 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?
  • OK, sorry to suggest you haven't but you've applied the rule to the relevant Virtual Server yes?
  • of course I applied rule to the relevant virtual server. is there any extra mark place in virtual server you have known?
  • 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?

     

  • 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"]: "
    }
    }
    
  • 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