Help Users Get Out Of The Stone Age with iRules

Today, I decided to take a break away from Twitter and catch up on some of the 1000's of blog posts I'm behind on reading.  So, I launched up Google Reader and came across Scott Hanselman's post on "IE6 Warning - Stop Living In The Past - Get off of IE6".  In his post, he talks about a movement to get folks off the ancient IE6 and onto a more recent, more secure browser.

In Scott's post, he showed off some of the stats for his blog revealing that close to 20% of the viewers of his site were using IE6.  Of course, I decided to see how his numbers matched up against IE users on DevCentral.  I pulled up a relevant sample of stats and found that a whopping 41% of DevCentral users are running IE6.

 

In retrospect, this sort of makes sense as DevCentral has a large population of corporate users who have less control on the software that runs on their laptops/PCs/etc.  So, for those, upgrading may not be possible.  But, I'm sure that a good portion of those IE6 users out there, just haven't taken the steps to upgrade to a more secure browsing platform.

Scott proposed including the following HTML to conditionally print a div blog notifying users that they should upgrade if they are running IE6 or below:

The bummer here is that this would require modifying every page in your application to supply this information.  Why not do it transparently at the network layer?  Well, that's just what I said!  So, I whipped up this iRule that you can deploy on your BIG-IP that will automagically add the warning information at the network layer.

The majority of the work here is done in the HTTP_RESPONSE_DATA event.  In there, it looks for a

tag and appends it with the warning information.  If no tag is found, it will put the content at the top of the page.
when RULE_INIT {
  # replace the value of the _uacct variable with your Google Analytics account.
  set warnie6 ""
}
when HTTP_REQUEST {
  # Don't allow data to be chunked
  if { [HTTP::version] eq "1.1" } {
    if { [HTTP::header is_keepalive] } {
       HTTP::header replace "Connection" "Keep-Alive"
    }
    HTTP::version "1.0"
  }
}
when HTTP_RESPONSE {
  if { [HTTP::header Content-Type] starts_with "text/html" } {
    if { [HTTP::header exists "Content-Length"] } {
      #log local0. "content length: [HTTP::header {Content-Length}]"
      set content_length [HTTP::header "Content-Length"]
    } else {
      set content_length 1000000
    }
    #log local0. "Collecting $content_length bytes"
    if { $content_length > 0 } {
       HTTP::collect $content_length
    }
  }
}
when HTTP_RESPONSE_DATA {
  #log local0. "Content Type: [HTTP::header Content-Type]"
  set idx [string first "
" [HTTP::payload]]
  if { -1 == $idx } {
    set idx [string first "" [HTTP::payload]]
  }
  #log local0. "html body tag found at $idx"
  if { -1 == $idx } {
    set idx 0
  } else {
    incr idx 6
  }
  HTTP::payload replace $idx 0 $::warnie6
}

This could easily be enhanced to remove the conditional check and only add the content depending on specific User-Agent strings thus reducing the network bandwidth overhead.

iRules really can do everything can't they B-).

Published Feb 24, 2009
Version 1.0

Was this article helpful?

2 Comments

  • Can you update the example to make warnie6 a local variable in HTTP_REQUEST or for v10+ change it to a static variable?

     

     

    set warnie6 ""

     

    ->

     

    set static::warnie6 ""

     

     

    And:

     

    $::warnie6

     

    ->

     

    $static::warnie6

     

     

    Thanks, Aaron