Fun with iRules: Haiku Error Responses

One of our stellar sales engineers, Rob Eberhardt, whipped up a fun iRule after one of his customers showed him some HTTP 404 errors returning haiku in BeOS.  The class, and iRule, followed by the result.  Enjoy!

The Class

Stored as an external class in /var/class/haiku_int.class (integer type).

1 := <span style="color: #006080;">"The web site you seek<br>Lies beyond our perception<br>But others await."</span>,
2 := <span style="color: #006080;">"Sites you are seeking<br>From your path they are fleeing<br>Their winter has come."</span>,
3 := <span style="color: #006080;">"A truth found, be told<br>You are far from the fold, Go<br>Come back yet again."</span>,
4 := <span style="color: #006080;">"Wind catches lily<br>Scatt'ring petals to the wind:<br>Your site is not found."</span>,
5 := <span style="color: #006080;">"These three are certain:<br>Death, taxes, and site not found.<br>You, victim of one."</span>,
6 := <span style="color: #006080;">"Ephemeral site.<br>I am the Blue Screen of Death.<br>No one hears your screams."</span>,

This continues on through 38, but the remaining ones removed for brevity.  Now the class reference:

<span style="color: #0000ff;">class</span> haiku_class {
type value
filename <span style="color: #006080;">"/var/class/haiku_int.class"</span>
separator <span style="color: #006080;">":="</span>
}

The iRule

<span style="color: #0000ff;">when</span> <span style="color: #cc6633;">RULE_INIT</span> {
<span style="color: #0000ff;">set</span> <span style="color: #0000ff;">static</span>::error_404 {

“#E7E7E7”>class=Section1>

<br>

class=MsoNormal align=center>

<span></span>
<span style="color: #0000ff;">table</span> width=500 height=258>
'background:#0078AD'>
'font-family:"Arial","sans-serif"; color: white; font-size: large'>
Error 404:
File Not Found

'background:white'>'font-family:"Arial","sans-serif"'>
    }  
}
when HTTP_RESPONSE {
  if { [HTTP::status] == 404 } {
    set randomnumber [expr { int (38 * rand()) }]
    set haiku [class match -value $randomnumber equals haiku_class]
    set response [concat $static::error_404 $haiku]
    HTTP::respond 200 content [subst $response]
  }
} 

The Result

Here’s a couple snapshots of the browser (I commented out the if clause to generate the error every request)

image_286085.png

image_286085.png

Related Articles

1 Like