Who say's iRules can't be fun? Not DevCentral user hunter32!

hunter32 and his coworker Tim sought out to confuse his users by sending a custom 404 (Page not found) response to users who requested invalid links (all from within an iRule).

I know the iRule Contest is over, but we had to much fun with this one. My self and a coworker Tim were trying to get better with iRules, and it is a little slow so we desicded to have a little fun. We wanted to replace the 404 error in our test lab with something more fun people to see. So we grab a wav from the Simpsons it is attach but it says "you tryed your best and you failed miserably, the lesson is never try" Attach is the rule. I know it is off topic but it was fun and caused a few people to wander what was wrong with the computers

In his HTTP Request handler, he disables chunked requests and sets a variable for later use.

  # Check for sensitive documents. 
  set check_content 1 

  # Don't allow data to be chunked. 
  if {[HTTP::version] == "1.1"} { 
    if {[HTTP::header is_keepalive]} { 
      # Adjust the Connection header. 
      HTTP::header replace "Connection" "Keep-Alive" 
    HTTP::version "1.0" 

Then, when a response comes back from the server in the HTTP_RESPONSE event, he looks for the HTTP 404 status code which indicates the requested url wasn't found. If a 404 is returned and his variable is set from the request event, the content length is calculated and he issues a HTTP::collect to pull down all the response from the server. This will trigger the HTTP_RESPONSE_DATA event.

  #check to see if it is a 404
  if { [HTTP::status] == "404" } {
    if {$check_content == 1} {
      set replace_now 1 
      # Calculate the amount to collect 
      set content_length 0 
      if {[HTTP::header exists "Content-Length"]} { 
        set content_length [HTTP::header "Content-Length"] 

      # If the header is missing, use a sufficiently large number 
      if {$content_length == 0} { 
        set content_length 4294967295 
      HTTP::collect $content_length 

And, when the response is sent back, if it the "replace_now" variable is set (from the previous event) then the response payload is replaced with and embedded control to play a classic Simpsons quote.

  set payload [HTTP::payload [HTTP::payload length]] 
  set fun_payload "


\n\n404 error Page not found

\n" #check to see if it should replace the content due to a 404 if {$replace_now == 1} { # Replace the content if there was any matches HTTP::payload replace 0 [HTTP::payload length] $fun_payload } }

Now, when their users try to request an invalid file, they get the following spoken to them by Homer Simpson: "You tried your best and you failed miserably. The lesson is: Never try"

Gotta love the flexibility of iRules!

Click here for the original post.